Multiple filtering on Facebook Marketing API (date range, country, impression_device etc.)

Viewed 1512

We would like to get marketing cost from Facebook Marketing API (Insights API - https://developers.facebook.com/docs/marketing-api/insights) based on multiple filtering (date range, country, impression_device etc.).

I can apply 1 filter at a time, e.g.:

  • "country": GET https://graph.facebook.com/v3.1/act_<ACCOUNT_ID>/insights?access_token=<ACCESS_TOKEN>&fields=["spend"]&time_range={"since":"YYYY-MM-DD","until":"YYYY-MM-DD"}&filtering=[{"field":"country","operator":"EQUAL","value":"GB"}]

  • "impression_device": GET https://graph.facebook.com/v3.1/act_<ACCOUNT_ID>/insights?access_token=<ACCESS_TOKEN>&fields=["spend"]&time_range={"since":"YYYY-MM-DD","until":"YYYY-MM-DD"}&filtering=[{field:"impression_device","operator":"IN","value":["iphone","ipad"]}]

BUT can't apply both in one query, getting the next response:

{
"error": {
    "message": "Service temporarily unavailable",
    "type": "OAuthException",
    "is_transient": false,
    "code": 2,
    "error_subcode": 1504018,
    "error_user_title": "Your request timed out",
    "error_user_msg": "Please try a smaller date range, fetch less data, or use async jobs",
    "fbtrace_id": "ADKphoammbM"
  }
}

I also tried to run report as async job (by making POST request as described here - https://developers.facebook.com/docs/marketing-api/insights/best-practices/#asynchronous), job is successfully started:

{
"id": "317371612321115",
"account_id": "<ACCOUNT_ID>",
"time_ref": 1545121794,
"async_status": "Job Started",
"async_percent_completion": 0,
"is_running": true,
"date_start": "2018-12-17",
"date_stop": "2018-12-17"
}

But then got "job failed" status:

{
"id": "317371612321115",
"account_id": "<ACCOUNT_ID>",
"time_ref": 1545121794,
"async_status": "Job Failed",
"async_percent_completion": 0,
"date_start": "2018-12-17",
"date_stop": "2018-12-17"
}

Is it possible to apply multiple filters as I described below?
Do some limits or docs how to apply multiple filters exist?
Thank you.

1 Answers

You can apply a filter array in the same request. Try:

filtering=[{field:"impression_device","operator":"IN","value":["iphone","ipad"]},{"field":"country","operator":"EQUAL","value":"GB"}]

This will return an impression iPhone or iPad device in GB.

Related