TJ1S
TJ1S

Reputation: 528

Facebook API endpoint to get campaigns of a certain objective?

I'm trying to fetch all of my ad campaigns from Facebook whose objective is "WEBSITE_CLICKS" (ie, driving visitors to your site). When I make a GET request against the following:

/act_myaccountid/adcampaign_groups?fields=objective,name

or, using the official Python Ads SDK:

fields = [facebookads.objects.AdCampaign.Field.objective, facebookads.objects.AdCampaign.Field.name]
campaigns = my_user_account.get_ad_campaigns(fields=fields)

I get something that looks like:

{
"data": [
{
  "objective": "NONE",
  "name": "name1",
  "id": "1234"
},
{
  "objective": "NONE",
  "name": "name2",
  "id": "567"
},

I'd like to be able to only get campaigns with that particular objective. Is there a way to do this? I read through the Ads documentation but didn't see anything.

Upvotes: 1

Views: 1904

Answers (1)

bjeavons
bjeavons

Reputation: 1133

It's not documented as far I've seen but the FB Ads Manager UI allows such filtering which also happens to work in external Graph API calls.

Make a call to the API with a filtering parameter like so:

filtering=[
  {
    "field":"<FIELD>",
    "operator":"IN",
    "value":[
      "<VALUE>"
    ]
  }
]

For example, your request would be:

/act_myaccountid/adcampaign_groups?fields=objective,name&filtering=[{"field":"objective","operator":"IN","value":["WEBSITE_CLICKS"]}]

Upvotes: 4

Related Questions