Get all stats (grouped by ad) for a specified day

analytics
api

#1

I’m new to the advertiser API from Twitter. But I want to know what the best way is to get all the stats (grouped by ad) for a specified day (with the fields campaign_id, campaign_name, ad_id, ad_name, cost, impressions and clicks). In the dashboard of Twitter I can make an export with all those fields, but in the API it looks like I have to do a lot of calls to the API. First I have to get all our campaign, then get all our line_items (groups) (for every call I can use 200 campaign_ids), then all our promoted_tweets (ads) (for every call I can use 200 line_item_ids) en for every tweet I can get the stats (with https://ads-api.twitter.com/2/stats/accounts/:account_id and for every call I can use up to 20 entity_ids) for a specified day. And every call for the stats I have to it twice, one for placement ALL_ON_TWITTER and one for placement PUBLISHER_NETWORK. Isn’t there a better way to get this information? Maybe I’m missing something.

We already use the API from Facebook and Google, but there you can get with 1 call all the results with campaign_id, campaign_name, ad_id, ad_name, cost, impressions and clicks. For Twitter I have to do more then 100 calls to the API to get the information we need, because we have more then 1000 campaigns with more then 10 promoted tweet for every campaign.


#2

Hello @wimvanderzicht!

I appreciate you providing so many details and doing so much prior research to make your work more efficient. Depending on the granularity of data you are trying to retrieve. You can use our synchronous or asynchronous stat endpoint to retrieve the stats you mentioned for up to 20 campaigns (entity_ids) at a time. If you review the following Metrics and Segmentation page, there is a chart that lists out the data you can retrieve at each entity level. This should help you decrease your overall API calls to get the information.

First I have to get all our campaign, then get all our line_items (groups) (for every call I can use 200 campaign_ids), then all our promoted_tweets (ads) (for every call I can use 200 line_item_ids) en for every tweet I can get the stats

From the GET campaigns endpoint, the default returns 200 campaign IDs, but you can request up to 1000 IDs in a single request.

And every call for the stats I have to it twice, one for placement ALL_ON_TWITTER and one for placement PUBLISHER_NETWORK.

Yes you will need to check the line item first to identify when to make a publisher network request for the line item itself or any of it’s promoted_tweets. In an ideal world you would not need to make these requests every time. If you were able to store the line item placement information (and update when it changes) so that you can avoid having to make extra calls for previously queried info.

Please let me know if there is anything else that does not make sense!