We are trying to find a curl call to get call volume based on categories in Apigee X and also see if there is no overage there. Can you please guide me if there is any curl call for the same?
@pshah30 wrote:
call volume based on categories in Apigee X
What is a category? I guess you are talking about Categories in the Integrated Developer Portal? If so, then.... there is no knowledge of the category, in the analytics data stream. Therefore to do what you want, you will gather API call volume for all API Products of concern, then aggregate them into categories, yourself.
Since the categories are portal-specific, You will need to query the apidocs (published products) for the portal, and gather the category ids.
GET :apigee/v1/organizations/:org/sites/:portalid/apidocs
Content-Type: application/json
Authorization: Bearer :token
In the above, :apigee
is apigee.googleapis.com
and :portalid
is the ID of your portal of interest. In response you will get something like this :
{
"status": "success",
"message": "one page of apidocs returned",
"requestId": "2084924254",
"errorCode": "",
"data": [
{
"siteId": "my-org-name-portalname",
"id": "670224",
"title": "apiproduct-example-1",
"description": "",
"published": true,
"anonAllowed": true,
"apiProductName": "apiproduct-example-1",
"requireCallbackUrl": false,
"imageUrl": "",
"categoryIds": [
"08a7454c-b60b-437b-b80c-fdc09837351a"
],
...
},
...
That tells you the API Product name and the category list for that API Product.
Then query the API volume for each API Product. To do that you need something like this:
:org = my-org-name
:env = eval
GET :apigee/v1/organizations/:org/environments/:env/stats/api_product?t=agg_percentile&select=sum(message_count)&sort&tsAscending=true&timeUnit=hour&accuracy=100&timeRange=12/03/2024%2015:44:31~12/05/2024%2015:44:31
Authorization: Bearer :token
and that gives you a response like so:
{
"environments": [
{
"name": "eval",
"dimensions": [
/* one of these for each product */
{
"name": "product-name-1",
"metrics": [
{
"name": "sum(message_count)",
"values": [
{
/* one of these for each time slot during the period of interest */
"timestamp": 1733263200000,
"value": "23503"
},
{
"value": "35927",
"timestamp": 1733266800000
},
...
Then aggregate all the results for the various products by category Id. Keep in mind that there is a N:M mapping of Products to Category. So you might have products that belong to multiple categories. Therefore the sum of volume for all categories will be higher than the sum of volume for all API Products, because volume for some API Products might be counted twice.
To map category ID to a category name, you can use this:
:site = my-org-name-portalname
:category = 08a7454c-b60b-437b-b80c-fdc09837351a
GET :apigee/v1/organizations/:org/sites/:site/apicategories/:category
Content-Type: application/json
Authorization: Bearer :token
and the result will be something like:
{
"status": "success",
"message": "ApiCategory item returned",
"requestId": "900297840",
"errorCode": "",
"data": {
"siteId": "my-org-name-portalname",
"name": "CategoryNameHere",
"id": "08a7454c-b60b-437b-b80c-fdc09837351a",
"updateTime": "0"
}
}
Thanks for the detailed information. Do you have curl call for puling volume per product?
Also I feel like if we pull product for each environments and if we have 10 environments, pulling the data on the dashboard is going to cause performance issue. What are your thoughts on it?
Yes, you will not be able to just pull all the analytics "on demand". I think you're planning to display this... in a dashboard? If I Were doing that I would want cached data. Have a job that runs periodically, maybe every 10 minutes, and collects all of that, and then the dashboard just reads from the cache. Something like that.
yes, it's in my answer above.
Hi,
I am not able to query for a specific product. Can you please give me a query for a specific product?
I hear you asking for the query. I gave it in my original answer. I've attached the image below. You're telling me "I am not able to query". But what have you tried? What did you observe? Is there an error you see? Participate in your own rescue here. Help me out.
You cannot insert api_product=xxxx in place of api_product.
With this you will get data on all api products:
GET :apigee/v1/organizations/:org/environments/:env/stats/api_product?t=agg_percentile&select=sum(message_count)&sort&tsAscending=true&timeUnit=hour&accuracy=100&timeRange=12/03/2024%2015:44:31~12/05/2024%2015:44:31&
if you want to filter on a specific API Product you can use the filter query param:
GET :apigee/v1/organizations/:org/environments/:env/stats/api_product?t=agg_percentile&select=sum(message_count)&sort&tsAscending=true&timeUnit=hour&accuracy=100&timeRange=12/03/2024%2015:44:31~12/05/2024%2015:44:31&&filter=(api_product eq ':product')
Authorization: Bearer :token