Facebook API - get performance data over time for every campaign

619 Views Asked by At

I am trying to find a way to leverage the Facebook business manager API to get campaign performance data for every campaign so I can create a report similar to this:

Facebook Business Manager Graph

Meaning I would need an endpoint returning these data:

  1. Campaign name
  2. Link Clicks
  3. Cost per Result
  4. Time

So that the response would look something like this:

[
 {
   "campaignName,": "Campaing_1,",
   "days,": "22/06/2020,",
   "valuesIndicator,": "actions:link_click,",
   "linkClick,": "27,",
   "costperResult": 4.95
 },
 {
   "campaignName,": "Campaing_1,",
   "days,": "23/06/2020,",
   "valuesIndicator,": "actions:link_click,",
   "linkClick,": "71,",
   "costperResult": 4.96
 },
 {
   "campaignName,": "Campaing_2,",
   "days,": "22/06/2020,",
   "valuesIndicator,": "actions:link_click,",
   "linkClick,": "55,",
   "costperResult": 4.97
 },
 {
   "campaignName,": "Campaing_2,",
   "days,": "23/06/2020,",
   "valuesIndicator,": "actions:link_click,",
   "linkClick,": "46,",
   "costperResult": 4.98
 },
 {
   "campaignName,": "Campaing_3,",
   "days,": "22/06/2020,",
   "valuesIndicator,": "actions:link_click,",
   "linkClick,": "51,",
   "costperResult": 4.99
 },
 {
   "campaignName,": "Campaing_3,",
   "days,": "23/06/2020,",
   "valuesIndicator,": "actions:link_click,",
   "linkClick,": "58,",
   "costperResult": 4.45
 }
]

Or something like that (this was just a quick conversion from CSV).

I was not successful in finding an endpoint that would return all this data in the Facebook API documentation.

Do you know if such an endpoint even exists?

Thank you very much

1

There are 1 best solutions below

0
On BEST ANSWER

I found that the {time_increment} parameter for the ad or campaign insight does exactly that.

If you need data for just one campaign follow the Facebook docs here.

If you need to export the data for all of your campaigns then you can achieve that by using your act_{AD_ACCOUNT_ID} instead of the {AD_SET_ID} and you will get all the data for all of your campaigns for said ad account.

So cURL call to get all this data might look something like this:

curl -X GET \
  'https://graph.facebook.com/v8.0/act_{AD_ACCOUNT_ID}/campaigns?fields=name%2Cstatus%2Cinsights.default_summary(true).limit(300).date_preset(lifetime).time_increment(1)%7Breach%2Cimpressions%2Cclicks%2Cinline_link_clicks%2Ccost_per_inline_link_click%7D&access_token={access_token}