Hello!
One change moving from Ads API v0 to v1 that I want to highlight is that stats endpoints do no longer allow end_time to be in the future.
For example, using hourly granularity in v0 would seemingly pad any future stats with zeros - something which I’ve grown quite accustomed to and is really convenient especially since when storing stats locally we store them using hourly granularity aligned by day. However, v1 won’t let you specify an end time in the future and thus introduces an extra layer of complexity when fetching stats for today as you can no longer rely on always having midnight aligned start and end times. It also makes it troublesome to fetch stats for today using daily granularity as outlined in this other thread Problem Stats V1 Granularity DAY.
Thus I cannot stress enough how nice and convenient it is to be able to specify an end_time in the future, and I’m hoping that you will considering bringing over this v0 end_time behavior to v1.
Here’s an example of fetching stats for today using midnight aligned dates in v0 and v1.
$ date && twurl -H ads-api.twitter.com "/0/stats/accounts/4no6av/line_items?metrics=billed_charge_local_micro&start_time=2016-04-05T00:00:00-0700&end_time=2016-04-06T00:00:00-0700&line_item_ids=4s8by&granularity=HOUR"|jsonpretty
Tue Apr 5 12:14:12 CDT 2016
{
"data_type": "stats",
"data": [
{
"start_time": "2016-04-05T07:00:00Z",
"billed_charge_local_micro": [
0,
0,
0,
0,
0,
0,
0,
10000,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"end_time": "2016-04-06T07:00:00Z",
"id": "4s8by",
"granularity": "HOUR"
}
],
"request": {
"params": {
"start_time": "2016-04-05T07:00:00Z",
"end_time": "2016-04-06T07:00:00Z",
"line_item_ids": [
"4s8by"
],
"account_id": "4no6av",
"granularity": "HOUR",
"metrics": [
"billed_charge_local_micro"
]
}
}
}
$ date && twurl -H ads-api.twitter.com "/1/stats/accounts/4no6av?entity=LINE_ITEM&metric_groups=BILLING&placement=ALL_ON_TWITTER&start_time=2016-04-05T00:00:00-07:00&end_time=2016-04-06T00:00:00-07:00&entity_ids=4s8by&granularity=HOUR"|jsonpretty
Tue Apr 5 12:13:30 CDT 2016
{
"errors": [
{
"code": "INVALID_PARAMETER",
"message": "Expected time before 2016-04-05T17:13:31Z, got \"2016-04-06 07:00:00 +0000\" for end_time",
"parameter": "end_time"
}
],
"request": {
"params": {
"start_time": "2016-04-05T07:00:00Z",
"entity_ids": [
"4s8by"
],
"end_time": "2016-04-06T07:00:00Z",
"placement": "ALL_ON_TWITTER",
"account_id": "4no6av",
"granularity": "HOUR",
"entity": "LINE_ITEM",
"metric_groups": [
"BILLING"
]
}
}
}