Accessing analytics data with the REST API

You can access your Analytics event data by using the API Connect REST API.

Before you begin

API Connect REST API calls are authenticated by using a bearer token in the authorization header. Use the toolkit credentials to request a bearer token. Toolkit credentials can be found in the API Manager UI:
  1. Log in to the API Manager UI.
  2. From the home page, click the Download toolkit tile.
  3. Download the Toolkit credentials.
  4. Open the downloaded credentials.json file, example:
    ...
      "toolkit": {
        "endpoint": "https://mgmt.api.example.com/api",
        "client_id": "7409693f-f726-48b4-8909-7c0d26f13e81",
        "client_secret": "5feeb0be-17f8-41a4-96d6-d40f33d69ef6"
      },
    ...
    Take note of the toolkit.client_id, toolkit.client_secret, and toolkit.endpoint from this file. You will use these to get your bearer token.

About this task

The Analytics REST API is documented here: Analytics REST API.

Important: The Analytics REST API was replaced in API Connect 10.0.5 and the new Analytics REST API is not backwards-compatible. If you are using a previous version of the REST API, update calls to use the new REST API.

Procedure

  1. Obtain an API key and exchange it for a bearer (access) token as explained in Calling an API Connect API programmatically in V10 Reserved.
  2. Use the returned bearer token to call the analytics REST API:
    # This call to /orgs/<provider_organization>/events requires a bearer token that was requested with provider org credentials:
    curl -v -k -H 'Accept: application/json' -H 'Authorization: Bearer <bearer_token>' -X GET --url 'https://<management_server_api_endpoint>/analytics/<analytics_service>/orgs/<provider_organization>/events'
    
    {
        "total": 300,
        "search_time": 3,
        "events": [...]
    }
    
    
    Where:
    • <management_server_api_endpoint> is the toolkit.endpoint, but with the /api at the end replaced with /analytics to access the analytics APIs.
    • <analytics_service> is the name of the Analytics service.
      Note: For V10 Reserved, the Analytics service name is ibm-managed-analytics-service-v2.