As our GET stats/accounts/:account_id endpoint describes, we expect the start_time and end_time to be expressed in ISO8601. Example: 2017-05-19T07:00:00Z.
Here is an example using twurl:
$ twurl -H ads-api.twitter.com "/2/stats/accounts/18ce54d4x5t?entity=LINE_ITEM&entity_ids=8u94t&start_time=2017-05-19T07:00:00Z&end_time=2017-05-26T07:00:00Z&granularity=TOTAL&placement=ALL_ON_TWITTER&metric_groups=ENGAGEMENT"
{
"data_type": "stats",
"time_series_length": 1,
"data": [
{
"id": "8u94t",
"id_data": [
{
"segment": null,
"metrics": {
"impressions": [
1233
],
"tweets_send": null,
"qualified_impressions": null,
"follows": null,
"app_clicks": null,
"retweets": null,
"likes": [
1
],
"engagements": [
58
],
"clicks": [
58
],
"card_engagements": null,
"poll_card_vote": null,
"replies": null,
"url_clicks": null,
"carousel_swipes": null
}
}
]
}
],
"request": {
"params": {
"start_time": "2017-05-19T07:00:00Z",
"segmentation_type": null,
"entity_ids": [
"8u94t"
],
"end_time": "2017-05-26T07:00:00Z",
"country": null,
"placement": "ALL_ON_TWITTER",
"granularity": "TOTAL",
"entity": "LINE_ITEM",
"platform": null,
"metric_groups": [
"ENGAGEMENT"
]
}
}
}
Note: use the -t flag to get the full trace of your request.
The same request using cURL:
$ curl -X GET "https://ads-api.twitter.com/2/stats/accounts/18ce54d4x5t?entity=LINE_ITEM&entity_ids=8u94t&start_time=2017-05-19T07%3A00%3A00Z&end_time=2017-05-26T07%3A00%3A00Z&granularity=TOTAL&placement=ALL_ON_TWITTER&metric_groups=ENGAGEMENT" -H 'Authorization: OAuth oauth_consumer_key="{consumer_key}", oauth_nonce="CcmsZAEEUDLhH1MkEpOzlpMfIBwOi5UrpcM9j5Q4", oauth_signature="{signature}", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1501127965", oauth_token="{token}", oauth_version="1.0"'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 649 100 649 0 0 2364 0 --:--:-- --:--:-- --:--:-- 2368
{
"data_type": "stats",
"time_series_length": 1,
"data": [
{
"id": "8u94t",
"id_data": [
{
"segment": null,
"metrics": {
"impressions": [
1233
],
"tweets_send": null,
"qualified_impressions": null,
"follows": null,
"app_clicks": null,
"retweets": null,
"likes": [
1
],
"engagements": [
58
],
"clicks": [
58
],
"card_engagements": null,
"poll_card_vote": null,
"replies": null,
"url_clicks": null,
"carousel_swipes": null
}
}
]
}
],
"request": {
"params": {
"start_time": "2017-05-19T07:00:00Z",
"segmentation_type": null,
"entity_ids": [
"8u94t"
],
"end_time": "2017-05-26T07:00:00Z",
"country": null,
"placement": "ALL_ON_TWITTER",
"granularity": "TOTAL",
"entity": "LINE_ITEM",
"platform": null,
"metric_groups": [
"ENGAGEMENT"
]
}
}
}
Given that this works when you specify the start_time and end_time values without the timestamp, the likely issue is with the oauth_signature. Remember:
Ensure that you’re encoding reserved characters appropriately within URLs and POST bodies before preparing OAuth signature base strings.
Source
Otherwise, you’ll see:
{
"errors": [
{
"code": "UNAUTHORIZED_ACCESS",
"message": "This request is not properly authenticated"
}
],
"request": {
"params": {}
}
}
This means that the 401 HTTP status code is correct.
+1 @imit8me for helping debug 