3

I'm trying to get Insight of an Ad-Account by filtering using multiple specific campaigns, I was able to filter with single specific campaigns Here is the code which I tried for single specific campaigns

https://graph.facebook.com/v12.0/act_YOUR_ACCOUNT_ID/insights?fields=actions,reach,impressions,clicks,cpc,spend&filtering=[{field: "campaign.id",operator:"CONTAIN", value: '123456789'}}]
Oleksii Tambovtsev
  • 2,666
  • 1
  • 3
  • 21
Ash18
  • 299
  • 3
  • 12

1 Answers1

2

You have 2 options:

  1. You can build a list of campaigns by your specific condition and then you use IN operator instead of CONTAIN operator like this:
https://graph.facebook.com/v12.0/act_YOUR_ACCOUNT_ID/insights?fields=actions,reach,impressions,clicks,cpc,spend&filtering=[{field: "campaign.id",operator:"IN", value: ['id1', 'id2', 'id3']}]
  1. You can try to use batch request like this (documentation here and here):
curl \
-F 'access_token=<ACCESS_TOKEN>' \
-F 'batch=[ \
  { \
    "method": "GET", \
    "relative_url": "v12.0/act_YOUR_ACCOUNT_ID/insights?fields=impressions,spend,ad_id,adset_id&filtering=[{field: "campaign.id",operator:"CONTAIN", value: '123456789'}]" \
  }, \
  { \
    "method": "GET", \
    "relative_url": "v12.0/act_YOUR_ACCOUNT_ID/insights?fields=impressions,spend,ad_id,adset_id&filtering=[{field: "campaign.id",operator:"CONTAIN", value: '222222222'}]" \
  }, \
]' \
'https://graph.facebook.com'
Oleksii Tambovtsev
  • 2,666
  • 1
  • 3
  • 21
  • Thanks for your effort, I tried both options , option 1 is giving blank response where as option 2 is giving error "(#100) Filter field id not supported in advanced filters." – Ash18 Dec 03 '21 at 13:00
  • @Ash18 I tried first option and it works for me. Are you sure that you use correct campaign ids in your request? Or maybe you don't have insights for given period, you can try add `date_preset=maximum` parameter to your request then to see insights for whole period. – Oleksii Tambovtsev Dec 04 '21 at 18:37
  • Tambovstev ,Thanks a lot, Option 1 worked for me I was doing a silly mistake I was checking for PAUSED status campaign – Ash18 Dec 06 '21 at 04:07