List details of all API Proxies in the Organization from ApigeeX

Hi,

Is there a way to get all the API Proxy Names and its details like basepath, host, metadata from ApigeeX?

Thanks!

 

 

Solved Solved
0 8 1,171
1 ACCEPTED SOLUTION

What do you mean by "usage count"? Traffic?

If it's traffic,  you can retrieve that data from the /stats APIs.  The stats API is pretty involved.  Here's an example to get message counts for all proxies in an environment

# get stats: message count
#
:org = my-apigee-org
:env = prod
:stat = sum(message_count)
:timerange = 04/01/2022%2000:00~04/06/2022%2000:00
:timeunit = day

GET :mgmtserver/v1/organizations/:org/environments/:env/stats/apis?select=:stat&timeRange=:timerange&timeUnit=:timeunit&limit=1024
Authorization: Bearer :token

how do we manage to get and refresh token automatically when the scheduled job runs?

Probably you want a machine account for that Java app. Is this Apigee X or Apigee Edge? For Apigee X you would use a service account. And then get a token from that service account. (you can do that with gcloud, or you can do it in your own code following this pattern.  a little while ago I wrote this Java sample to show how to do it from within Java.)  For Edge you would use a machine account to get a token. I don't have Java code to show that but it's  not too complicated.  After you get the token, it looks similar. Use the token as a bearer token.

View solution in original post

8 REPLIES 8

Check below reference - credits @dchiesa1 

https://github.com/DinoChiesa/apigee-scanner

Yes, have you looked at the Apigee API ?

You can list the full set of api proxies using this resource. and then use the same resource to get data around basepath of the proxyendpoints and so on.

You can write a script to do that stuff.

What are you really solving for?   What will you use the information for?

 

Thanks for your help!

Yes, with those management APIs we can retrieve the details. We need to fetch it from a Java application in a schedule manner. Frist need to collect all proxy details and update the usage count of each proxy in our own DB.

What is the option to get the usage count of proxies?

Another concern is, this is running from an external system, how do we manage to get and refresh token automatically when the scheduled job runs?

 

What do you mean by "usage count"? Traffic?

If it's traffic,  you can retrieve that data from the /stats APIs.  The stats API is pretty involved.  Here's an example to get message counts for all proxies in an environment

# get stats: message count
#
:org = my-apigee-org
:env = prod
:stat = sum(message_count)
:timerange = 04/01/2022%2000:00~04/06/2022%2000:00
:timeunit = day

GET :mgmtserver/v1/organizations/:org/environments/:env/stats/apis?select=:stat&timeRange=:timerange&timeUnit=:timeunit&limit=1024
Authorization: Bearer :token

how do we manage to get and refresh token automatically when the scheduled job runs?

Probably you want a machine account for that Java app. Is this Apigee X or Apigee Edge? For Apigee X you would use a service account. And then get a token from that service account. (you can do that with gcloud, or you can do it in your own code following this pattern.  a little while ago I wrote this Java sample to show how to do it from within Java.)  For Edge you would use a machine account to get a token. I don't have Java code to show that but it's  not too complicated.  After you get the token, it looks similar. Use the token as a bearer token.

Yes, it's traffic.

We are using Apigee X and need to confirm about service account, that's also clear now.

Thanks much for the detailed solution!

One more refinement on the above.

Need to get the usage count of each endpoint URI grouped by the developer app.

https://apigee.googleapis.com/v1/organizations/:org/environments/:env/stats/proxy_pathsuffix?select=sum(message_count)&timeRange=:daily&timeUnit=day&filter=(developer_app eq ':each-developer-app-name')

Is there any better option to get via API?

Yes, you can get stats on the endpoint URI.  I mentioned earlier that the /stats API is pretty extensive. You will need to use some of the other parameters in the stats API to get that data. 

You can refer to this reference. You want to try the proxy_pathsuffix and proxy_basepath dimensions

got it, thank you very much!