How to get Promoted Tweet Ids OR Line Item Ids which have some analytics data in stats apis for a particular date range




Is there a way I can get the promoted tweet ids which have stats for a given date range? Actually I am looking for some stats end point which can group on promoted tweets level and I get only those promoted tweets which actually have some stats in given date range.

According to documentation the current option I know of is to grab all the promoted tweets via GET accounts/:account_id/promoted_tweets for a particular account and then use the stats end point of promoted tweet to see the stats. Note that because our system is making campaigns with dashboard so I don’t have any value of line_item_id , or promoted_tweet_id in my database and due to same I can not apply any filter. All I am looking to find an efficient way to get the stats from twitter for each day and ignore the non-required promoted tweet ids. Because if I do this for all promoted_tweet_ids for everyday then my system will not remain efficient due to addition of more advertiser accounts and more campaigns on daily bases.

Actually in our system we planned to use dashboard to create the campaigns but we want the stats data in our database for each day. i.e we will have scheduled Cron-job for each day and it will grab the statistics from end point “GET stats/accounts/:account_id/promoted_tweets” and will save it in database.

The other end point as recommended in Analytic docs is line_items but this would also have same problem, this way I’ll have to grab all the line_items for an account and then do the calculation. Please suggest some appropriate solution for my scenario if there is any.

Is there any API Edge or Plan to make one, where it is possible to directly get effected Promotted Tweets in a particular date range?

@mahsanamin thanks for your question.

We have an example script that demonstrates how to do this in Python available here.

In that script, we pull all line items and all promoted tweets for an account using with_deleted=true. In your case, since you know the campaign IDs, you could also use the parameter campaign_ids=XXXX,XXXX,XXXX to grab just the line items you are concerned about.

twurl -H "/0/accounts/XXXXX/line_items?with_deleted=true&campaign_ids=XXXXX,XXXXX,XXXX"

Then before making any stats calls, you can follow the behavior of best practices example and filter out any line items or promoted tweets that couldn’t have any data for your specified time window.

Never pull real-time data older than 7 days, and as a reminder:

  • All analytics metrics are locked and will not change after 24 hours, with the exception of billed_charge_local_micro.
  • The billed_charge_local_micro metric is an estimate for up to 3 days after the data is returned.
  • After 24 hours, this metric can decrease due to credits for overspend (ads served after the given end_time) and for billable events that are determined to be junk. This metric changes minimally after 24 hours.

Related documentation:

Question about POST request and how to get report for only promoted_tweets in a specified date range
Ads API - How to filter entities by activity period

@brandonmblack Thank you for detailed reply. The “check” function seems to help me in my situation. Unluckily my system database don’t know the campaign Ids as everything is happening from dashboard and we can’t enter any campaign_id manually in our database. Actually our database only has record of tweet_ids which we just use them from campaigns via dashboard.However thank you the recommendation this was most important I needed to know from twitter team.

I only have one question/suggestion though, Why there is no end point in stats API which can just return data grouped as line-items so we could avoid this “check” function at the development side also. I apologize that I’ll have to give a reference of outside Twitter, actually our system doing almost same with Facebook “insights” and there is an option to group on ad-groups (i.e line_items) in that case and in real I was wondering something similar here. Please consider it just suggestion or just a question, I know all systems are designed differently and have inner complexities.


@mahsanamin I’m in complete agreement with you.

While the current Ads API stats endpoints have lots of flexibility and offer true real-time stats, they’re quite complex to use. Some of the SDKs we’re building help with this a little bit, but there’s still plenty of room for improvement.

We’re right now discussing and planning what the v1 version (the next major release) of our stats might look like. It’s still quite a ways off, but rest assured there’s a big focus on making stats on Twitter simpler to use and removing a lot of the complexity you see in the API today.

Hopefully in the not-so-distant future we have a much easier to use offering for both real-time stats as well as historical stats.


@brandonmblack , Sorry I had to bug you again in the solved question. A little thing I needed to confirm so I think its better to ask in the same thread.

The above code is using “end_time” property in check function via “promoted_tweets” end point.Now one of my campaign is finished/ended but I can’t see “end_time” in response. However I can see “end_time” property in “campaigns” Api, see below my sample api calls including my account_id and relevant ids.

My actual question is when “end_time” property will be returned under promoted_tweets api end point ?

twurl -H "/0/accounts/18ce53zkiav/promoted_tweets/cj76j"
twurl -H "/0/accounts/18ce53zkiav/line_items/3feee"
twurl -H “/0/accounts/18ce53zkiav/campaigns/3clr0”

Thank you in Advance.