Use Access Token

Once you have successfully acquired an access_token, you can use it to make requests to any PerspioTalk endpoint. The token must be included in the Authorization header with a type of Bearer along with the Perspio tenant Id and Perspio tenant subscription key.

🚧

Prerequisite

  • Valid access token (access_token)
  • Perspio tenant subscription key (Ocp-Apim-Subscription-Key)
  • Perspio tenant Id (tid)

👍

Test it here first!

If you have the three prerequisite parameters handy, you can test all of the documented API endpoints within these very docs. Test it out with the Get Tenant Info endpoint.

Use Access Token Example

Now that you have an access token, subscription key and tenant id parameters, you should be able to successfully interact with all of the available PerspioTalk endpoints. The structure and behaviour of API requests are consistent across all endpoints, so implementing subsequent calls into your integrations should be seamless.

For this example, we'll use the popular Get Assets interface. This API is intended to return a list of all available assets within a specific Perspio tenant. As defined in the linked documentation, this interface requires a simple GET request with no request body required.

API Endpoint

GET <https://talk.perspio.io/assets/v3/>

Request Example

GET /assets/v3/
Host: https://talk.perspio.io
Authorization: Bearer eyJ...
tid:in-...
Ocp-Apim-Subscription-Key: PerspioTalkSubKey
Accept: application/json

Request Headers

HeaderValue
AuthorizationBearer access_token
Ocp-Apim-Subscription-KeyPerspioTalk Subscription Key (Ocp-Apim-Subscription-Key)
tidPerspio Tenant Id (tid)
Acceptapplication/json

Step 2: Cache Access Token

Because fetching new tokens is expensive, we recommend using a token cache to prevent unnecessary requests.

After retrieving an 'access_token', store it in an in-memory cache, like Memcached, or a built-in ASP.NET cache service. By default, Access Tokens are valid for 60 minutes, but we recommend setting the expiration time to around 50 minutes to allow for a buffer.

When you need a token, first check the cache for a valid token. If the token expired, get a new one and store it in the cache for 50 minutes.

📘

Expired Token

Expired tokens return a 401: Unauthorized error. This error should be handled to refresh the token.