Authentication Request
Add Authentication Request
Click on + Add requests and enter the request step name e.g. Authenticate with Spotify API.
Expand the Request section, from the drop-down change the request method to POST and enter the following URL:
https://accounts.spotify.com/api/token
In the Payload body section enter the following:
grant_type=client_credentials
Next, add two request headers with the following key/value pairings:
- CONTENT-TYPE: application/x-www-form-urlencoded
- AUTHORIZATION: Basic {{env.encoded_auth}}
Expand the Validation section and add the following extraction:
- Extract from Response body JSON $.access_token as access_token.
This will parse the JSON payload that is received from the Spotify API, extract the access token and store it as a custom variable.
Search Request
Add Search Request
Click on + Add Request to add the next step. Name the step Search for Tracks named “Up around the bend”.
Expand the Request section and change the request method to GET and enter the following URL:
https://api.spotify.com/v1/search?q=Up%20around%20the%20bend&type=track&offset=0&limit=5
Next, add two request headers with the following key/value pairings:
- CONTENT-TYPE: application/json
- AUTHORIZATION: Bearer {{custom.access_token}}
Expand the Validation section and add the following extraction:
- Extract from Response body JSON $.tracks.items[0].id as track.id.
Click on < Return to test to return to the test configuration page. And then click Save to save the API test.