Search code examples
facebookfacebook-graph-apifacebook-ads-apifacebook-marketing-api

Facebook API 'Invalid rule JSON format' When Creating Custom Web Audience


I am using Graph API 12.0 to create a custom web audience and getting "Invalid rule JSON format" error. I believe I am using the exact format specified here

Below is my request:

{
  "name": "test",
    "rule": {
    "inclusions": {
      "operator": "or",
      "rules": [
        {
          "event_sources": [
            {
              "type": "pixel",
              "id": PIXEL_ID
            }
          ],
          "retention_seconds": 600
        }
      ]
    }
  },
  "retention_days": "1",
  "prefill": "1"
}

Solution

  • It turns out "filter" was a required field even though it is stated optional in the documents. I think this is a bug within Facebook API. What if I don't need any filters?

    Below request works successfully:

    {
      "name": "test",
        "rule": {
        "inclusions": {
          "operator": "or",
          "rules": [
            {
              "event_sources": [
                {
                  "type": "pixel",
                  "id": PIXEL_ID
                }
              ],
              "retention_seconds": 600,
              "filter": {
                        "operator": "and",
                        "filters": [{
                            "field": "url",
                            "operator": "regex_match",
                            "value": "."
                        }]
                    }
            }
          ]
        }
      },
      "retention_days": "1",
      "prefill": "1"
    }