Cloud Blog

Programmatically download API usage statistics

WSO2 API Cloud has a rich set of reports built in. In addition to that, we have now added the ability to programmatically pull API invocation data via a REST API so you can do your own reporting and integrate it with your other systems.

For this example, I will pull down statistics on the API calls that I made on a particular day. Here’s how:

1. Follow our earlier blog post to register your client and obtain your OAuth token (steps 1 and 2 in that blog post).

Important: on step 2.3 (Request the token), make sure to use apim:subscribe as the scope:

$ curl -k -d "grant_type=password&username=email@org_key&password=pwd&scope=apim:subscribe" -H "Authorization: Basic Base64EncodedclientIdclientSecret"


2. Invoke the statistics API:

2.1 Create a json file with the parameters – the timeframe and the statistics ID:

  • getTopAppUsers – Top Users For Applications
  • getAppApiCallType – API Usage from Resource Path
  • getPerAppAPIFaultCount – Faulty Invocations per Application
  • getProviderAPIUsage – API Usage per Application

For example, here’s the stat_payload.json that I used:

    "statisticsType" : "getProviderAPIUsage",
    "toDate":"2018-02-02 00:00",
    "fromDate": "2018-02-01 00:00"

2.2 Invoke the API to get the stats:

$ curl -X POST -H "Authorization: Bearer fac22c3b-efc1-3c16-92e8-56ab96a0f2f6" -H "Content-Type: application/json" -d @stat_payload.json

  "message":"Successfully retrieved the statistics data for the statistics type getProviderAPIUsage for the user",
       \"appName\":\"Default Application\",
            \"apiName\":\"Heroes (\",
            \"apiName\":\"Phones (\",
            \"apiName\":\"WorldBank (\",

This is just one of the APIs that WSO2 Cloud exposes. To see all other APIs, check out our documentation.





Recent Posts

Most Popular Posts