14

For filtering param, This page demo-ed IN and CONTAIN,

https://developers.facebook.com/docs/marketing-api/insights/v2.4#filtering

curl -G \
-d "filtering=[{'field':'adgroup.delivery_info','operator':'IN','value':['archived']}]" \
-d "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/insights"

curl -G \
-d "filtering=[{'field':'adcampaign.name','operator':'CONTAIN','value':'18-25'}]" \
-d "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/insights"

But the information is very limited. Where can I find more info about the usage of filtering? e.g. How it should be if I want to filter out all items with blank (ad campaign) names? Or only the items with some attr (any type, e.g. dict or array) not empty (undefined).

mitnk
  • 3,127
  • 2
  • 21
  • 28
  • 9
    Check the parameters section: https://developers.facebook.com/docs/marketing-api/insights/v2.4#parameters for filtering. `Filters on the report data. This parameter is an array of filter object. Each filter object has three fields: 'field', 'operator' and 'value'. Valid filter operator could be ('EQUAL', 'NOT_EQUAL', 'GREATER_THAN', 'GREATER_THAN_OR_EQUAL', 'LESS_THAN', 'LESS_THAN_OR_EQUAL', 'IN_RANGE', 'NOT_IN_RANGE', 'CONTAIN', 'NOT_CONTAIN', 'IN', 'NOT_IN', 'ANY', 'ALL', 'NONE').` You can then maybe experiment with these values. – bangdel Sep 22 '15 at 13:41
  • I wonder if Filtering is unavailable in v2.7 and 2.8. – Ryan Mar 03 '17 at 16:12
  • 5
    @Bandel: They do not mention about what field we can use. Very bad document. – dalmate Jun 01 '17 at 08:48
  • 1
    5 years later and Facebook's documentation around filtering is still quite lacking. I seek to solve the exact same problem as OP - omitting records with blank/unset values from the API response. Curious if you ever solved this / what you ended up doing? – Eric Seastrand Jul 29 '20 at 18:23

2 Answers2

2

Docs are not very rich, but it's possible.

Docs says it only works for /insight route, but its working for /adsets too

Use filtering query param like this :

curl -G \
-d 'access_token=<ACCESS_TOKEN>' \
-d 'filtering=[{field:"ad.impressions",operator:"GREATER_THAN",value:0},]' \
'https://graph.facebook.com/v14.0/act_<ACCOUNT_ID>/insights'

Use filtering parameter only to retrieve insights for ad objects with data. The field value specified in filtering uses DOT notation to denote the fields under the object. Please note that filtering with STARTS_WITH and CONTAIN does not change the summary data. In this case, use the IN operator.

Add more filters like this (note its and AND operator between each filter):

-d 'filtering=[{field:"ad.impressions",operator:"GREATER_THAN",value:0},{field:"ad.spend",operator:"GREATER_THAN",value:100}]' 

Here are two little "explanations" from official docs :

Ref 1

Ref 2

BorisD
  • 1,611
  • 17
  • 22
0

Perhaps here you can find which fields are filterable and which operators are supported.

https://developers.facebook.com/docs/marketing-api/ad-rules/overview/evaluation-spec

Description in section Metadata filters supported by Trigger and Schedule Based rules