Possible to specify date_preset with insights edge in Facebook Ads API?
Asked Answered
R

2

6

For the Marketing API, I know that I'm able to make one call to retrieve all of the adsets from a certain account along with their insights, but am I able to specify the date_preset for the insights edge in that same call?

For example, the following gives me lifetime insights stats:

/v2.4/{accountID}/adcampaigns?fields=insights

To be clear - I know this is possible to retrieve by making separate calls for each adset id (where I know I can specify the date_preset); instead, I'd like to do this via the call where I get a long list of the ad sets plus their insights details in one go.

Royster answered 15/7, 2015 at 6:41 Comment(0)
V
6

Yes this is possible using query expansion, however you probably should not do it in this anyway.

Using query expansion results in multiple requests being executed in one HTTP call, in this case one to get all the adcampaigns, and then N requests where N is the number of adcampaigns returned. This will in turn affect your rate limiting.

The most efficient way to request all insights for all adcampaigns (ad sets) is instead to request them at the account level, specifying aggregation level:

/v2.4/act_{ADACCOUNT_ID}/insights?date_preset=last_7_days&level=campaign

This requires just 1 request, or the number of requests to retrieve the total number of pages.

If you really want to achieve this with query expansion, you can do the following for example:

/v2.4/act_{ADACCOUNT_ID}/adcampaigns?fields=insights.date_preset(last_30_days).time_increment(all_days)

You can see the parameters to insights that would normally be query parameters of the form param_name=param_value are now in the form of param_name(param_value).

Vanvanadate answered 15/7, 2015 at 15:22 Comment(0)
P
3

To specify the date_preset , here is the correct format . Its important to use insights as edge to get the date_preset filtering .

/v2.10/act_{ADACCOUNT_ID}/insights?fields=impressions,clicks,ctr,unique_clicks,unique_ctr,spend,cpc&date_preset=last_3d

The above one is tested with latest Graph Api version(2.10) as of now . FOr more info related to the date_preset values refer to there api docs .

https://developers.facebook.com/docs/marketing-api/insights/parameters

Paton answered 13/10, 2017 at 7:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.