Ads API - Which Campaign REST endpoint to use to get Clicks, Impressions, Cost,


#1

Hi,

I have quite large number of campaigns and I would like to pull the following stats through Ads API. There are quite a few endpoints documented here https://dev.twitter.com/ads/campaigns. I am not sure which endpoint to use.

Data Required:

Clicks,
Impressions,
Cost,
Installs
Country,
Device

Currently, data is exported as csv file manually from https://ads.twitter.com through UI. I am in the process of automating it so the system can pull clicks, impressions, spend, installs automatically for each campaign throughout the day. I tried using the following REST endpoints

GET stats/accounts/:account_id/campaigns - to fetch list of campaigns and I get the list of campaign names, their campaign ids and all successfully.

GET stats/accounts/:account_id/campaigns/:id - to fetch “clicks”, “installs”, “impressions” and “spends” for each campaign.
I am getting HTTP/200 with json response but the metrics are zero for given campaign id while the campaign returned by UI has data. I noticed the campaign Id returned in exported CSV file is in a numeric while the one returned by Ads API is alphanumeric for the same campaign name. I am using the campaign id returned by the Ads API

I have large number of campaigns, if there is a way to get these stats in 1 REST call, it would be great. Please advise which REST endpoint to use to get these metrics. Do i need to get all campaign ids first before making individual call to fetch stats / is there a batch call I can make.

Appreciate your time and help


#2

Hey @nirmal,

The endpoints you should be making use of are indeed GET stats/accounts/:account_id/campaigns and GET stats/accounts/:account_id/campaigns/:id. Those are the two endpoints you need to get all campaign-related stats.

What do your requests look like? Could you give us a couple of examples using twurl? What about the responses? What do those look like?


#3

Hi @andrs,

Thanks for your response. I need to get all campaigns first so that i know the CampaignId I need to use for the endpoints you mentioned. I thought the first endpoint is to fetch all campaigns info but that endpoint, GET stats/accounts/:account_id/campaigns needs a query parameter “campaign_ids” which I don’t have, please advise which endpoint to use to fetch all campaigns and their ids.

I tried the below endpoint to get list of all campaigns, GET accounts/:account_id/campaigns , i got list of campaigns, when I tried to use those campaign Ids for the GET endpoints you suggested above, I got the json with zero values, see URL 2 and 3 response below

I have removed information which can point to my account like account Id for security reasons. You will see something like “removed” , “ACCTID REMOVED”

1. URL to fetch Campaigns: GET accounts/:account_id/campaigns
I used this endpoint to fetch all campaigns with their id’s and used these ids as campaign ids in the above endpoint to fetch stats on campaign. See part of json response below:

twurl -H ads-api.twitter.com “/0/accounts/ACCTIDREMOVED/campaigns?sort_by=start_time-desc&count=1000”

{ "account_id" : "removed", "created_at" : "2015-05-15T17:22:20Z", "currency" : "USD", "daily_budget_amount_local_micro" : removed, "deleted" : false, "end_time" : null, "funding_instrument_id" : "removed", "id" : "2h0jp", "name" : "TPN_DK_removed_320x50_RON_Android", "paused" : false, "reasons_not_servable" : [ ], "servable" : true, "standard_delivery" : true, "start_time" : "2015-05-15T17:17:00Z", "total_budget_amount_local_micro" : removed, "updated_at" : "2015-05-15T17:22:20Z" },

In this case, I used the id: 2h0jp as campaign id in the below URLs. For the same campaign name, the id is 7 digit numeric when fetched through UI in https://ads.twitter.com

I am not sure the Campaign Id returned by this endpoint is the correct one. I get a json response back with HTTP/200 with these ids but not actual stats.

When I check the stats returned by using “campaign name” manually, for this given campaign Id, I have stats from UI export but not through API. Please note I only used campaign name as the ids did not match.


2. For URL: GET stats/accounts/:account_id/campaigns , I got the following json response. As you can see the values are zero.

twurl -H ads-api.twitter.com “/0/stats/accounts/ACCOUNTIDREMOVED/campaigns?campaign_ids=2h0jp&start_time=2015-05-26T22:00:00Z&granularity=DAY”

{ "data" : [ { "billed_charge_local_micro" : [ 0, 0 ], "billed_engagements" : [ 0, 0 ], "billed_follows" : [ 0, 0 ], "end_time" : "2015-05-28T13:00:06Z", "granularity" : "DAY", "id" : "2h0jp", "mobile_conversion_installs" : [ 0, 0 ], "mobile_conversion_installs_breakdown" : { "assisted" : [ 0, 0 ], "post_engagement" : [ 0, 0 ], "post_view" : [ 0, 0 ], "total" : [ 0, 0 ] }, "promoted_account_follow_rate" : [ 0.0, 0.0 ], "promoted_account_follows" : [ 0, 0 ], "promoted_account_impressions" : [ 0, 0 ], "promoted_account_profile_visits" : [ 0, 0 ], "promoted_tweet_app_install_attempts" : [ 0, 0 ], "promoted_tweet_app_open_attempts" : [ 0, 0 ], "promoted_tweet_search_card_engagements" : [ 0, 0 ], "promoted_tweet_search_clicks" : [ 0, 0 ], "promoted_tweet_search_engagement_rate" : [ 0.0, 0.0 ], "promoted_tweet_search_engagements" : [ 0, 0 ], "promoted_tweet_search_favorites" : [ 0, 0 ], "promoted_tweet_search_follows" : [ 0, 0 ], "promoted_tweet_search_impressions" : [ 0, 0 ], "promoted_tweet_search_replies" : [ 0, 0 ], "promoted_tweet_search_retweets" : [ 0, 0 ], "promoted_tweet_search_url_clicks" : [ 0, 0 ], "promoted_tweet_timeline_card_engagements" : [ 0, 0 ], "promoted_tweet_timeline_clicks" : [ 0, 0 ], "promoted_tweet_timeline_engagement_rate" : [ 0.0, 0.0 ], "promoted_tweet_timeline_engagements" : [ 0, 0 ], "promoted_tweet_timeline_favorites" : [ 0, 0 ], "promoted_tweet_timeline_follows" : [ 0, 0 ], "promoted_tweet_timeline_impressions" : [ 0, 0 ], "promoted_tweet_timeline_replies" : [ 0, 0 ], "promoted_tweet_timeline_retweets" : [ 0, 0 ], "promoted_tweet_timeline_url_clicks" : [ 0, 0 ], "start_time" : "2015-05-26T22:00:00Z" } ], "data_type" : "stats", "request" : { "params" : { "account_id" : "ACCOUNTID REMOVED", "campaign_ids" : [ "2h0jp" ], "granularity" : "DAY", "start_time" : "2015-05-26T22:00:00Z" } } }

3. For URL: GET stats/accounts/:account_id/campaigns/:id , I got the following output for the same campaign Id

twurl -H ads-api.twitter.com “/0/stats/accounts/ACCTIDREMOVED/campaigns/2h0jp?start_time=2015-05-26T22:00:00Z&granularity=DAY”

{ “data” : { “billed_charge_local_micro” : [ 0,
0
],
“billed_engagements” : [ 0,
0
],
“billed_follows” : [ 0,
0
],
“end_time” : “2015-05-28T13:03:30Z”,
“granularity” : “DAY”,
“id” : “2h0jp”,
“mobile_conversion_installs” : [ 0,
0
],
“mobile_conversion_installs_breakdown” : { “assisted” : [ 0,
0
],
“post_engagement” : [ 0,
0
],
“post_view” : [ 0,
0
],
“total” : [ 0,
0
]
},
“promoted_account_follow_rate” : [ 0.0,
0.0
],
“promoted_account_follows” : [ 0,
0
],
“promoted_account_impressions” : [ 0,
0
],
“promoted_account_profile_visits” : [ 0,
0
],
“promoted_tweet_app_install_attempts” : [ 0,
0
],
“promoted_tweet_app_open_attempts” : [ 0,
0
],
“promoted_tweet_search_card_engagements” : [ 0,
0
],
“promoted_tweet_search_clicks” : [ 0,
0
],
“promoted_tweet_search_engagement_rate” : [ 0.0,
0.0
],
“promoted_tweet_search_engagements” : [ 0,
0
],
“promoted_tweet_search_favorites” : [ 0,
0
],
“promoted_tweet_search_follows” : [ 0,
0
],
“promoted_tweet_search_impressions” : [ 0,
0
],
“promoted_tweet_search_replies” : [ 0,
0
],
“promoted_tweet_search_retweets” : [ 0,
0
],
“promoted_tweet_search_url_clicks” : [ 0,
0
],
“promoted_tweet_timeline_card_engagements” : [ 0,
0
],
“promoted_tweet_timeline_clicks” : [ 0,
0
],
“promoted_tweet_timeline_engagement_rate” : [ 0.0,
0.0
],
“promoted_tweet_timeline_engagements” : [ 0,
0
],
“promoted_tweet_timeline_favorites” : [ 0,
0
],
“promoted_tweet_timeline_follows” : [ 0,
0
],
“promoted_tweet_timeline_impressions” : [ 0,
0
],
“promoted_tweet_timeline_replies” : [ 0,
0
],
“promoted_tweet_timeline_retweets” : [ 0,
0
],
“promoted_tweet_timeline_url_clicks” : [ 0,
0
],
“start_time” : “2015-05-26T22:00:00Z”
},
“data_type” : “stats”,
“request” : { “params” : { “account_id” : “ACCTID REMOVED”,
“campaign_id” : “2h0jp”,
“granularity” : “DAY”,
“start_time” : “2015-05-26T22:00:00Z”
} }
}


Thanks,
Nirmal


#4

@nirmal we have this information documented in some of the links you’re already referencing. I’d recommend you take a quick re-read through our Getting Started guide and all the related resources on that page.

For analytics specifically, we have the following guides which contain some of the answers you’re looking for that you should make sure you’re up to speed on:

https://dev.twitter.com/ads/campaigns/analytics
https://dev.twitter.com/ads/campaigns/analytics-best-practices
https://dev.twitter.com/ads/campaigns/metrics-derived


#5

Hi,

We have large number of campaigns, most of them were TPN and some of them are not. I can see data is being returned for non TPN campaigns. 0 is being returned for TPN campaigns.

Here, Getting stats on TPN campaigns , your colleague mentioned on March 23, TPN campaigns are in closed beta. Please advise when TPN campaign stats will be available through API.


#6

@nirmal, for TPN you’ll need to pull the TPN-specific metrics. I’ve just followed-up on the linked thread you mentioned.