How do you pass a time range to a stats API?

sgilson
Participant V

The SmartDocs page for the "Retrieve and Filter Metrics for a Dimension", says to pass a timeRange as:

MM/DD/YYYY HH:MM~MM/DD/YYYY HH:MM. 

For example:

8/24/2015 1200:00~9/20/2015 1200:00 

That works fine in SmartDocs because it URL encodes the time range in the generated curl command:

curl -X GET "https://api.enterprise.apigee.com/v1/organizations/sgilson/environments/test/stats/apis?select=sum(message_count)&timeRange=8%2F24%2F2015%201200%3A00~9%2F20%2F2015%201200%3A00&timeUnit=day" 

But in a straight curl command, how do you specify the time range? The doc says specify the date as MM/DD/YYYY%HH:MM using a % to precede HH:MM, as in:

curl  https://api.enterprise.apigee.com/v1/o/{org_name}/environments/test/stats/target_url?"select=sum(is_error)&timeRange=8/08/2015%1200:00~9/15/2015%1200:00&timeUnit=week" 

But that generates an error:

{
  "code" : "Invalid parameter - timeRange",
  "message" : "Invalid parameter - timeRange",
  "contexts" : [ ]
} 

If I do it like SmartDocs, by omitting the %, then I get no response at all:

curl  https://api.enterprise.apigee.com/v1/o/{org_name}/environments/test/stats/target_url?"select=sum(is_error)&timeRange=8/08/2015 1200:00~9/15/2015 1200:00&timeUnit=week" 

How do I pass the range then in curl?

Thanks,

Stephen

Solved Solved
2 4 2,007
1 ACCEPTED SOLUTION

Hi @sgilson ,

Below curl command works for me,

curl -X GET -H "Authorization: Basic XXXXXXXXXX" -H "Cache-Control: no-cache" -H "Postman-Token: 9be9d357-c446-b438-f60f-06067e4667bc" 'https://api.enterprise.apigee.com/v1/o/ORG/environments/test/stats/apis?select=sum(message_count)&timeRange=08/15/2015%2000:00~11/01/2015%2000:00&timeUnit=month'

In MM/DD/YYYY%20HH:MM using a %20 to precede HH:MM

View solution in original post

4 REPLIES 4

Hi @sgilson ,

Below curl command works for me,

curl -X GET -H "Authorization: Basic XXXXXXXXXX" -H "Cache-Control: no-cache" -H "Postman-Token: 9be9d357-c446-b438-f60f-06067e4667bc" 'https://api.enterprise.apigee.com/v1/o/ORG/environments/test/stats/apis?select=sum(message_count)&timeRange=08/15/2015%2000:00~11/01/2015%2000:00&timeUnit=month'

In MM/DD/YYYY%20HH:MM using a %20 to precede HH:MM

Thanks @Anil Sagar. I'll update the doc to say that you have to precede HH:MM with %20.

Stephen

Anytime @sgilson 🙂 , Glad query is resolved.

@Stephen Gilson late to the party, just wanted to share that it also works if you use a "+" between the date and time, e.g.:

curl -v 'https://api.enterprise.apigee.com/v1/o/{orgname}/environments/{envname}/stats/apis?select=sum(message_count),sum(error_count)&sort=DESC&sortby=sum(message_count),sum(error_count)&t=agg_api&timeRange=11/11/2015+12:20~11/11/2015+12:25&timeUnit=minute&tsAscending=true&limit=5'