2. • The Anypoint Platform for APIs gathers powerful analytics data for
each API that is managed using the platform. This data is displayed
visually in your API’s dashboard, but many scenarios require access to
the raw data so that it can be analyzed or transformed. To meet this
need, the Analytics Reporting API makes it easy to create a report
that queries the desired data and exposes it via an API endpoint. You
can also create reports that span more than one API, or create
different reports for the same API.
3. Creating a Report
• The following steps show you how to create a report.
• As an Organization Administrator, you have access to the Analytics
Dashboards for your organization. Go
to http://anypoint.mulesoft.com/analytics to access your Analytics
Dashboards. You can also click Analytics in the drop-down menu in
the top-right of the window.
4. • On the top menu, click Manage Reports.
• On the Manage Reports page, click New to create a new report.
• On the Create Report page, select your desired data source, range,
format, and fields. A URL generates for the configured report, which
represents the endpoint that can be called.
• Click Save Report to save the report and make it available at the
specified endpoint. You are redirected to the Manage Reports page.
5. Running a Report in the Browser
• The following steps show you how to run a report from the Manage
Reports page in the dashboard.
• On the Manage Reports page, click Run for the specified report.
• After the report has finished running, the resulting file is saved in the
data format that was selected when the report was created. For
example, ShippingAPI Usage.csv. This file contains all of the raw
analytics data for the parameters you specified in the report.
6. Calling a Report Programmatically
• The following steps show you how to call the report’s API endpoint
and programmatically retrieve the analytics data.
7. • Open a new terminal window and execute the following command:
• TOKEN=$(curl -s https://anypoint.mulesoft.com/accounts/login -d
"username=<YOUR-USERNAME>&password=<YOUR-PASSWORD>" |
jq -r .access_token)
• This command sends a request to the authentication servers of the
Anypoint Platform and, if the request is successful, returns an access
token that’s stored in the $TOKEN variable. The value of this variable
is displayed below:
8. • Once the access token has been received, it must be appended to the
Authorization header in the request to the Analytics Reporting API endpoint for
your report. To make a request to this endpoint, copy it from the Manage Reports
page in the Analytics dashboard. Using the $TOKEN variable from the previous
step, include it in the next request as shown below:
• curl -H "Authorization: bearer $TOKEN"
"https://anypoint.mulesoft.com/analytics/1.0/47f40446-9f0b-43c0-a8ca-
c7aea5136f32/events?format=csv&apiIds=2447&startDate=2014-12-
02&endDate=2015-01-
08&fields=Application%20Name.Client%20IP.Resource%20Path > output.csv"
• If the request is successful, the response includes a CSV file (as requested) that
downloads as a file with the specified name (output.csv) in the directory where
the curl request was made.
9. Data Fields for Reports
• Your report can query data for one, many, or all of the available data
fields. These fields are explained in the table below.
•