Introduction

Besides accessing Insights metrics through Admin Portal, Insights Premium users can access their metrics using API.

To read about the available metrics, categories, and their limitations, refer to the general Insights API documentation.

Authentication

To authenticate to the Insights API, follow these steps:

  1. Set environment variables.

    Provide the login details required to authenticate to the Admin Portal URL.

    Set TOKEN to an empty value that will be filled in automatically once you are granted the authentication token in further steps.

    BASE_URL:   https://admin.pubnub.com/api/me
    TOKEN:
    LOGIN: <Admin Portal e-mail>
    PASSWORD: <Admin Portal password>
  2. Get the token.

    Request a token by calling the https://admin.pubnub.com/api/me URL.

    curl --location --request POST 'https://admin.pubnub.com/api/me' \
    --header 'Content-Type: application/json' \
    --data-raw '{
    "email": "'$LOGIN'",
    "password":"'$PASSWORD'"
    }'
  3. Save the token.

    Get a token in response and add it to environment variables.

    RESPONSE=$(curl -s --location --request POST 'https://admin.pubnub.com/api/me' \
    --header 'Content-Type: application/json' \
    --data-raw '{
    "email": "'$LOGIN'",
    "password":"'$PASSWORD'"
    }')
    echo $RESPONSE
    export TOKEN=$(echo $RESPONSE | jq -r .result.token)