Stevie Star
Stevie Star

Reputation: 2371

Facebook Ads API via Javascript SDK - How to get ad accounts &campaigns for business manager account

I have an Angular 5 app where I need to grab some data from my ad accounts via a Business Manager account that I have been made an admin of. I'm having trouble figuring out which API documentation I need to follow and which endpoints to call.

I'm just trying to figure out how to get data from the Graph API Explorer that Facebook provides and when I try something like this:

/v2.12/<business-account-id>/adaccounts I get an error:

{
  "error": {
    "message": "(#12) adaccounts field is deprecated for versions v2.11 and higher",
    "type": "OAuthException",
    "code": 12,
    "fbtrace_id": "AV2JHORP+bN"
  }
}

I have all the correct permissions set with my access token, though I'm not sure what to call to get that data. There are a lot of different API docs and I'm not sure which ones to follow.

Has anyone run into this as well?

Upvotes: 0

Views: 1588

Answers (1)

John Washam
John Washam

Reputation: 4103

I recently wrote a blog post explaining in-depth how to do this, and here is a brief overview:

Ad Accounts Owned by Your Business

To get the list of ad accounts that your Business account owns, you can make a call to the following URL:

/<API_VERSION>/<BUSINESS_ID>/owned_ad_accounts

Read more at: https://developers.facebook.com/docs/marketing-api/businessmanager/assets

Ad Accounts Owned by Your Clients

You can pull all ad accounts owned by other Business accounts by using the client_ad_accounts edge:

/<API_VERSION>/<BUSINESS_ID>/client_ad_accounts?fields=id,name,business

Requesting the business field will give you information about the Business that is sharing the ad account to you.

(Thanks to user skinnyas123 for reminding me about the new edge to get clients' ad accounts! I began using it awhile back and forgot to update this answer.)

Upvotes: 1

Related Questions