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. Use your credentials to request a bearer token:
    curl -v -k -X POST -d '{"username": "<username>", "password": "<password>", "realm": "<realm>", "client_id": "<client_id>", "client_secret": "<client_secret>", "grant_type": "password"}' -H 'Content-Type: application/json' -H 'Accept: application/json' https://<management_server_platform_api_endpoint>/token
    Where:
    • <username> is either the admin user or provider org owner, depending on whether you want to access cloud or provider organization scoped analytics data.
    • <password> is the password for the specified <username>.
    • <realm> is the user registry realm for the specified <username>. By default the realm is admin/default-idp-1 for the admin user, and provider/default-idp-2 for provider organization users.
    • <client_id> is the client ID from the "toolkit" section of the credentials.json file, or as provided by your API Connect cloud administrator.
    • <client_secret> is the client secret from the "toolkit" section of the credentials.json file, or as provided by your API Connect cloud administrator.
    • <management_server_platform_api_endpoint> is the platform API endpoint from the "toolkit" section of the credentials.json file, or as provided by your API Connect cloud administrator.
    The bearer token is returned in the access_token property:
    {
        "access_token": "<bearer_token>",
        "token_type": "Bearer",
        "expires_in": 28800
    }

    Note the expires_in value, which is the number of seconds before the token expires. After expiry you need to request a new bearer token.

  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": [...]
    }
    
    # This call to /cloud/events requires a bearer token that was requested with admin credentials:
    curl -v -k -H 'Accept: application/json' -H 'Authorization: Bearer <bearer_token>' -X GET --url 'https://<management_server_api_endpoint>/analytics/<analytics_service>/cloud/events'
    
    {
        "total": 45543,
        "search_time": 36,
        "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.