To get the API access token:
- In the collections tree, right-click New Collection and then select Add Request.
- In the name field, enter Get API Access Token.
- From the drop-down list, select POST.
-
In the Enter request URL field, enter the following,
replacing {domain_name} with your environment's domain name:
https://{domain_name}/identity/connect/token
- On the Body tab, select x-www-form-urlencoded.
-
On the
Params tab, add the following key/value pairs to the query
params:
- grant_type: authorization_code
- code: {{code}}
-
redirect_uri:
https://{domain_name}/{api_name}/swagger/oauth2-redirect.html
Replace {domain_name} with your environment's domain name and {api_name} with the API you are targeting (heart, identity, repository, policy, analytics).
-
client_id: API Client’s ID. The ID can be found in the API’s
appsettings.json file in the following
locations:
Heart Client ID HeartServer:Swagger:ClientId
Identity Client ID IdentityServer:Swagger:ClientId
Repository Client ID RepositoryServer:Swagger:ClientId
Policy Client ID PolicyServer:Swagger:ClientId
Analytics Client ID Swagger:ClientId
-
On the Tests tab, as the Tests
body enter the following, replacing {api_name} with the API you
are targeting (Heart, Identity, Repository, Policy, Analytics)::
var jsonData = JSON.parse(responseBody); pm.collectionVariables.set("{api_name}AccessToken", jsonData.access_token);
-
Click
Send.
Note: The access token will now be in the variable {api_name}AccessToken, with {api_name} being the name of the API you are targeting.
- Verify that the status code is 200.
- Click Save.