Search code examples
facebookfacebook-graph-apifacebook-ads-apifacebook-marketing-api

How to filter Facebook Ads Insights by time range?


I'm getting info about my ads throug the endpoint https://graph.facebook.com/v11.0/act_<ad_account_ID>?fields=ads{insights{ad_name,clicks}} but returns data from the last 30 days, and I need to get information just about a specific time range. How can I do it? I'm trying to use the parameter time_range={'since':'2021-09-01','until':'2021-09-03'} but doesn't work.

By the way, I tried to use the endpoint https://graph.facebook.com/v11.0/act_<ad_account_ID>/insights?level=ad&fields=ad_name,clicks&time_range={'since':'2021-09-01','until':'2021-09-03'} and it works the way I need, but when all the fields needed are passed (using ad_name and clicks just as an example) it returns an error about the amount of data returned, saying it's too much, and it doesn't occur in the other endpoint.


Solution

  • For my experience it is useful to select carefully the metrics, avoiding the redundant ones and to perform asynchronous or, better, batch requests; if you have to retrieve lot of data please switch to these kind of methods and avoid sincrhonous requests.

    You can read more here.

    I suggest you moreover to avoid insights data call at account level; it is better to pass a bunch of ids and make batch call.