How to set time range for /stats if end_time null?

analytics
api

#1

I’m trying to get /stats on all line_items and promoted_tweets. /stats requires both start_time and end_time to be specified neither are optional. start_time and end_time can be found at the campaign level. However, some campaigns have end_time = null, regardless of whether the campaign is sill “active” (ie servable = true). So, given that campaigns don’t always have an end time, and /stats requires an end_time, how do I go about getting these stats? If a campaign was created say a year ago, do I have to query stats in 7 day interval (since 7 day is the max allowed) from the campaign start_date, until I reach the present date (ie 52 requests)?


#2

First, to be clear, none of our stats endpoints require end_time.

If end_time is not passed, it will be interpreted as CURRENT_TIMESTAMP. This is true both in version 0 and version 1 of our analytics endpoints.

That said, I would still recommend passing the current timestamp yourself. Note that we’ll never have stats in the future, so should be safe to pass up til now in any of your queries.

For backfilling data, you’ll need to break your queries into several chunks. For our synchronous endpoint, the max time for a single request is 7 days. We’d recommend using our asynchronous endpoint for backfills as you can get more data from that endpoint in a single query.


#3

So do the docs say, but there is a bug, and end_time is actually required. Please see Stats start_time and end_time


#4

end_time is indeed a required parameter, although the documentation says it’s optional. If not passed, you get the following error in the response:

 "errors": [
        {
            "code": "MISSING_PARAMETER",
            "message": "\"end_time\" is a required parameter",
            "parameter": "end_time"
        }
    ],

I tried using the asynchronous endpoint as suggested:

 twurl -H https://ads-api.twitter.com -X POST '/1/stats/job/accounts/18ce53vxx4a?entity=PROMOTED_TWEET&entity_ids=sys6&start_time=2015-09-28T08:00:00Z&metric_groups=ENGAGEMENT,BILLING&placement=ALL_ON_TWITTER&granularity=TOTAL'

"errors":[  
      {  
         "code":"ROUTE_NOT_FOUND",
         "message":"The requested resource could not be found"
      }
   ]

I’m assuming this error means that the endpoint is not yet available. According to upcoming-changes, “v1 generally available” effective_date is set to March 31 2016.


#5

Could you put the twurl request where you get end time as a required param?


#6
twurl -H https://ads-api.twitter.com '/1/stats/accounts/18ce53vxx4a?entity=PROMOTED_TWEET&entity_ids=b5osg&start_time=2015-09-28T07:00:00Z&metric_groups=ENGAGEMENT,BILLING,MEDIA,WEB_CONVERSION,MOBILE_CONVERSION,VIDEO&placement=ALL_ON_TWITTER&granularity=TOTAL' | python -m json.tool                                                                                              
    {
        "errors": [
            {
                "code": "MISSING_PARAMETER",
                "message": "\"end_time\" is a required parameter",
                "parameter": "end_time"
            }
        ],
        "request": {
            "params": {
                "account_id": "18ce53vxx4a",
                "entity": "PROMOTED_TWEET",
                "entity_ids": [
                    "b5osg"
                ],
                "granularity": "TOTAL",
                "metric_groups": [
                    "ENGAGEMENT",
                    "BILLING",
                    "MEDIA",
                    "WEB_CONVERSION",
                    "MOBILE_CONVERSION",
                    "VIDEO"
                ],
                "placement": "ALL_ON_TWITTER",
                "start_time": "2015-09-28T07:00:00Z"
            }
        }
    }

#7

Hi!,

You’re right @noodlycious In API v1 is a required param.

I think we should consider that as an issue regard the fact API v1 Enpoints are in Preview mode

Ads API Versioning Announced Phase Effective Date Status 2016-03-01 v1 preview 2016-03-15 On Schedule 2016-03-01 v1 generally available 2016-03-31 On Schedule 2016-03-01 v0 no longer supported 2016-06-30 On Schedule

Regards!


#8

end_time is wrongly required in v0 too ( Stats start_time and end_time ).


#9

I did a test a few minutes ago, and I’ve obtained expected response:

twurl -H https://ads-api.twitter.com '/0/stats/accounts/18ce54alb6p?start_time=2016-03-26T07:00:00Z&granularity=TOTAL' | python -m json.tool { "data": { "billed_engagements": [ 2400 ], "billed_follows": [ 0 ], "conversion_order_quantity": [ 0 ], "conversion_purchases": [ 0 ], "conversion_sale_amount": [ 0 ], "conversion_sign_ups": [ 0 ], "end_time": "2016-03-30T08:53:14Z", "granularity": "TOTAL", "id": "18ce54alb6p", "mobile_conversion_installs": [ 544 ], "mobile_conversion_installs_breakdown": { "assisted": [ 0 ], "post_engagement": [ 259 ], "post_view": [ 285 ], "total": [ 544 ] }, "mobile_conversion_logins": [ 0 ], "mobile_conversion_logins_breakdown": { "assisted": [ 0 ], "post_engagement": [ 0 ], "post_view": [ 0 ], "total": [ 0 ] }, "mobile_conversion_purchases": [ 0 ], "mobile_conversion_purchases_breakdown": { "assisted": [ 0 ], "post_engagement": [ 0 ], "post_view": [ 0 ], "total": [ 0 ] }, "mobile_conversion_sign_ups": [ 0 ], "mobile_conversion_sign_ups_breakdown": { "assisted": [ 0 ], "post_engagement": [ 0 ], "post_view": [ 0 ], "total": [ 0 ] }, "promoted_account_follow_rate": [ 0.0 ], "promoted_account_follows": [ 0 ], "promoted_account_impressions": [ 0 ], "promoted_account_profile_visits": [ 0 ], "promoted_tweet_app_install_attempts": [ 2779 ], "promoted_tweet_app_open_attempts": [ 5 ], "promoted_tweet_search_card_engagements": [ 2 ], "promoted_tweet_search_clicks": [ 8 ], "promoted_tweet_search_engagement_rate": [ 0.0186219739292365 ], "promoted_tweet_search_engagements": [ 10 ], "promoted_tweet_search_favorites": [ 0 ], "promoted_tweet_search_follows": [ 0 ], "promoted_tweet_search_impressions": [ 537 ], "promoted_tweet_search_replies": [ 0 ], "promoted_tweet_search_retweets": [ 0 ], "promoted_tweet_search_url_clicks": [ 0 ], "promoted_tweet_timeline_card_engagements": [ 2777 ], "promoted_tweet_timeline_clicks": [ 4272 ], "promoted_tweet_timeline_engagement_rate": [ 0.007794845280646196 ], "promoted_tweet_timeline_engagements": [ 7116 ], "promoted_tweet_timeline_favorites": [ 233 ], "promoted_tweet_timeline_follows": [ 34 ], "promoted_tweet_timeline_impressions": [ 912911 ], "promoted_tweet_timeline_replies": [ 10 ], "promoted_tweet_timeline_retweets": [ 23 ], "promoted_tweet_timeline_url_clicks": [ 29 ], "start_time": "2016-03-26T07:00:00Z" }, "data_type": "stats", "request": { "params": { "account_id": "18ce54alb6p", "granularity": "TOTAL", "start_time": "2016-03-26T07:00:00Z" } } }


#10

I see. Then the bug is only for granularity=DAY, and maybe for granularity=HOUR too. I tested only daily stats.


#11

:stuck_out_tongue:

`twurl -H https://ads-api.twitter.com ‘/0/stats/accounts/18ce54alb6p?start_time=2016-03-25T23:00:00Z&granularity=DAY’ | python -m json.tool
{
“data”: {
“billed_engagements”: [
490,
751,
576,
556,
115
],
“billed_follows”: [
0,
0,
0,
0,
0
],
“conversion_order_quantity”: [
0,
0,
0,
0,
0
],
“conversion_purchases”: [
0,
0,
0,
0,
0
],
“conversion_sale_amount”: [
0,
0,
0,
0,
0
],
“conversion_sign_ups”: [
0,
0,
0,
0,
0
],
“end_time”: “2016-03-30T09:05:19Z”,
“granularity”: “DAY”,
“id”: “18ce54alb6p”,
“mobile_conversion_installs”: [
111,
130,
136,
146,
44
],
“mobile_conversion_installs_breakdown”: {
“assisted”: [
0,
0,
0,
0,
0
],
“post_engagement”: [
45,
64,
63,
76,
22
],
“post_view”: [
66,
66,
73,
70,
22
],
“total”: [
111,
130,
136,
146,
44
]
},
“mobile_conversion_logins”: [
0,
0,
0,
0,
0
],
“mobile_conversion_logins_breakdown”: {
“assisted”: [
0,
0,
0,
0,
0
],
“post_engagement”: [
0,
0,
0,
0,
0
],
“post_view”: [
0,
0,
0,
0,
0
],
“total”: [
0,
0,
0,
0,
0
]
},
“mobile_conversion_purchases”: [
0,
0,
0,
0,
0
],
“mobile_conversion_purchases_breakdown”: {
“assisted”: [
0,
0,
0,
0,
0
],
“post_engagement”: [
0,
0,
0,
0,
0
],
“post_view”: [
0,
0,
0,
0,
0
],
“total”: [
0,
0,
0,
0,
0
]
},
“mobile_conversion_sign_ups”: [
0,
0,
0,
0,
0
],
“mobile_conversion_sign_ups_breakdown”: {
“assisted”: [
0,
0,
0,
0,
0
],
“post_engagement”: [
0,
0,
0,
0,
0
],
“post_view”: [
0,
0,
0,
0,
0
],
“total”: [
0,
0,
0,
0,
0
]
},
“promoted_account_follow_rate”: [
0.0,
0.0,
0.0,
0.0,
0.0
],
“promoted_account_follows”: [
0,
0,
0,
0,
0
],
“promoted_account_impressions”: [
0,
0,
0,
0,
0
],
“promoted_account_profile_visits”: [
0,
0,
0,
0,
0
],
“promoted_tweet_app_install_attempts”: [
573,
875,
655,
633,
144
],
“promoted_tweet_app_open_attempts”: [
0,
2,
1,
2,
0
],
“promoted_tweet_search_card_engagements”: [
0,
0,
1,
1,
0
],
“promoted_tweet_search_clicks”: [
3,
4,
1,
0,
0
],
“promoted_tweet_search_engagement_rate”: [
0.031578947368421054,
0.03418803418803419,
0.012048192771084338,
0.006944444444444444,
0.0
],
“promoted_tweet_search_engagements”: [
3,
4,
2,
1,
0
],
“promoted_tweet_search_favorites”: [
0,
0,
0,
0,
0
],
“promoted_tweet_search_follows”: [
0,
0,
0,
0,
0
],
“promoted_tweet_search_impressions”: [
95,
117,
166,
144,
35
],
“promoted_tweet_search_replies”: [
0,
0,
0,
0,
0
],
“promoted_tweet_search_retweets”: [
0,
0,
0,
0,
0
],
“promoted_tweet_search_url_clicks”: [
0,
0,
0,
0,
0
],
“promoted_tweet_timeline_card_engagements”: [
573,
875,
653,
633,
144
],
“promoted_tweet_timeline_clicks”: [
952,
1292,
1112,
870,
181
],
“promoted_tweet_timeline_engagement_rate”: [
0.0077674234665422795,
0.008267402219523177,
0.007426267769997878,
0.0075736787223533285,
0.00842532673518589
],
“promoted_tweet_timeline_engagements”: [
1532,
2185,
1785,
1518,
332
],
“promoted_tweet_timeline_favorites”: [
50,
56,
68,
58,
11
],
“promoted_tweet_timeline_follows”: [
4,
7,
14,
6,
3
],
“promoted_tweet_timeline_impressions”: [
197234,
264291,
240363,
200431,
39405
],
“promoted_tweet_timeline_replies”: [
1,
3,
1,
4,
1
],
“promoted_tweet_timeline_retweets”: [
2,
8,
5,
5,
3
],
“promoted_tweet_timeline_url_clicks”: [
9,
8,
6,
7,
0
],
“start_time”: “2016-03-25T23:00:00Z”
},
“data_type”: “stats”,
“request”: {
“params”: {
“account_id”: “18ce54alb6p”,
“granularity”: “DAY”,
“start_time”: “2016-03-25T23:00:00Z”
}
}
}

Regards!`


#12

I see, @hector_borras :slight_smile: Then they must have solved this in the meantime. Thank you for the tests!


#13

To confirm, end_time is in fact required in v1 and must be rounded to an hour (i.e. 0 minutes and 0 seconds). Take a look at the migration guide now published.


#14

Thanks @jaakkosf,

But

I get an access denied

Regards!


#15

Thanks @hector_borras. Just refreshed our cache, give that link another try?


#16

Solved!

Thanks for your support!


#17

Thanks for the confirmation!


#18