Drill-Down Custom Dimensions in Analytics API

Not applicable

Our APIs are location-driven and so we are recording a custom dimension of "location."

Using Management UI, a Custom Report can allow us to start with a list of transactions by Developer App, and then drill down from there to see all the locations that a particular Developer App requested.

But I can't figure out how to replicate this same drill down using the Analytics APIs. I want to retrieve the count per location but filter by Developer App. How can I go about this? Thanks!

Solved Solved
0 9 1,414
2 ACCEPTED SOLUTIONS

Not applicable

Hi @Jeof Oyster , Are you saying that you are unable to filter using a custom dimension ?

That is possible . Can you try with 'in' instead of 'IN' ?

example :

/v1/o/org/e/senv/stats/x_forwarded_for_ip?select=sum(message_count)&timeRange=06/01/2015%2000:00~06/03/2015%2000:00&timeUnit=day&filter=%28x_forwarded_for_ip+in+%27120.70.20.228%27%29

View solution in original post

Not applicable

Hello Jeof

What in custom reports is shown as a drill down, is translated into the API call as a filter condition. A filter condition is very similar to a WHERE clause in SQL and if you are familiar with it, you will find the Analytics filter easy to use. Please keep in mind that the syntax is similar, but that it will not support all the flexibility that you have in a real transactional DB dialect.

Filters are sent as a query parameter named “filter”.

Every condition has the following form:

{dimension} {operator} {value or values to compare}

Where operator can be “eq” (=), “ne” (!=), “gt” (>), “lt” (<), “ge” (>=), “le” (<=), “in” and “notin” (not in)

A note here, operators are case sensitive, “IN” will not work, you need to use “in”.

For example, you can say:

…/{org}/environments/prod/stats/{custom dimension}?select=sum(message_count)&timeRange=06/01/2015%2000:00~06/03/2015%2000:00&timeUnit=day&filter=(client_id in 'ABC123')

You can use in a filter any dimension listed in your environment schema, the same thing with the group by dimension (the fragment after ../stats/ ).

To retrieve the schema for your environments, use:

…/{org}/environments/{env}/analytics/admin/schema?type=fact

You can also use several conditions using “and” or “or” operands.

Note. Keep your parenthesis in your filter condition at minimum, handling nested parenthesis is not well supported.

I hope this helps.

View solution in original post

9 REPLIES 9

Not applicable

Hi Mike,

Yes I've read through all the docs but can't find a definitive list of the keys by which I can filter. For example, this page:

http://apigee.com/docs/analytics-services/reference/analytics-reference#reportfilters

Has some examples but only along the lines proxy, code, and error and is more about the comparison operators.

The link you posted implies I can't filter my custom dimension by the developer app name, is that true? How is this done, then, in the Custom Reports?

I tried filtering by a non-app value like the consumer key, but still get the same error. Here's an example:

https://api.enterprise.apigee.com/v1/o/{org}/environments/prod/stats/{customdimension}?select=sum(message_count)&timeRange=06/01/2015%2000:00~06/03/2015%2000:00&timeUnit=day&filter=%28client_id+IN+'ABC123'%29

And get this error:

{
  "code": "Invalid filter expression (client_id IN 'ABC123')",
  "message": "Invalid filter expression (client_id IN 'ABC123')",
  "contexts": []
}

@Mike Dunker did you or anyone else have any other thoughts on this one?

( @scott@apigee.com)

Hi @Jeof Oyster, I'm trying to find an analytics expert to answer your question. Sorry I couldn't!

No worries, just wanted to keep the question on the radar. 🙂

Not applicable

Hi @Jeof Oyster , Are you saying that you are unable to filter using a custom dimension ?

That is possible . Can you try with 'in' instead of 'IN' ?

example :

/v1/o/org/e/senv/stats/x_forwarded_for_ip?select=sum(message_count)&timeRange=06/01/2015%2000:00~06/03/2015%2000:00&timeUnit=day&filter=%28x_forwarded_for_ip+in+%27120.70.20.228%27%29

Not applicable

Hello Jeof

What in custom reports is shown as a drill down, is translated into the API call as a filter condition. A filter condition is very similar to a WHERE clause in SQL and if you are familiar with it, you will find the Analytics filter easy to use. Please keep in mind that the syntax is similar, but that it will not support all the flexibility that you have in a real transactional DB dialect.

Filters are sent as a query parameter named “filter”.

Every condition has the following form:

{dimension} {operator} {value or values to compare}

Where operator can be “eq” (=), “ne” (!=), “gt” (>), “lt” (<), “ge” (>=), “le” (<=), “in” and “notin” (not in)

A note here, operators are case sensitive, “IN” will not work, you need to use “in”.

For example, you can say:

…/{org}/environments/prod/stats/{custom dimension}?select=sum(message_count)&timeRange=06/01/2015%2000:00~06/03/2015%2000:00&timeUnit=day&filter=(client_id in 'ABC123')

You can use in a filter any dimension listed in your environment schema, the same thing with the group by dimension (the fragment after ../stats/ ).

To retrieve the schema for your environments, use:

…/{org}/environments/{env}/analytics/admin/schema?type=fact

You can also use several conditions using “and” or “or” operands.

Note. Keep your parenthesis in your filter condition at minimum, handling nested parenthesis is not well supported.

I hope this helps.

Not applicable

Yay! That was it - "in" needs to be lower case.

Note that at this page of documentation (and maybe elsewhere) the operators are in all-caps.

@Jeof Oyster - I updated the documentation on that page to reflect that the operators should be lowercase. Thanks for helping fix the docs!