How to Call Spotify API from Okta Workflows (with OAuth 2.0)

In this guide:

  1. Okta Workflows guides
  2. Call Spotify API
  3. Related Okta Workflows guides
  4. Okta Workflows resources

Okta Workflows guides

Okta Workflows guides are questions and answers from the community office hours, the #okta-workflows channel on MacAdmins Slack, and other places. Read all the other guides.

How do you call Spotify API that uses OAuth authentication from Okta Workflows? 

This guide will teach you how to call Spotify API, which uses OAuth authentication from Okta Workflows. You can use this example to call other APIs that use OAuth authentication.

Call Spotify API

You want to call Spotify’s Get Current User’s Playlists API.

This is how the curl request looks:

curl --request GET \
--url https://api.spotify.com/v1/me/playlists \
--header 'Authorization: Bearer <access_token>'

Create a Spotify account

  1. Create a Spotify account, if you don’t have one.

Create an app

An app will provide an access token to make calls to Spotify API.

  1. Create an app.
  2. For the Redirect URIs field, use the following redirect URIs to connect to Okta Workflows:
    • Okta Workflows Preview:
      • https://oauth.workflows.oktapreview.com/oauth/httpfunctions/cb
    • Okta Workflows Production:
      • https://oauth.workflows.okta.com/oauth/httpfunctions/cb

This is how the app looks when using the Okta Workflows Preview callback URI:

Spotify app with callback URI.

In the following section, you will create a connection in Okta Workflows with information from this app.

Create a connection

  1. Go to the Connections page in Okta Workflows.
  2. To create a new connection, click + New Connection.
  3. Select the API Connector connection.
  4. Enter Spotify connection for the Name field.
  5. Enter Spotify API connection for the Description field.
  6. Select OAuth from the Auth Type list.
  7. Enter https://accounts.spotify.com/api/token for the Access Token Path field.
  8. Enter https://accounts.spotify.com/authorize for the Authorize Path field.
  9. Return to the app you created in Spotify. Click Settings. Copy and paste the Client ID and Client Secret values into the connection popup.
  10. Enter playlist-read-private in the Scope field. The API lists the scopes it requires.

The connection setup looks like this:

Spotify connection information.
  1. Click Create.
Spotify authorization.
  1. Sign in and agree to allow the app you created on Spotify to access your playlist information.

You created a connection to Spotify.

Call the Spotify API

  1. Create a flow.
  2. Add the API Connector – Get card.
  3. From the Connections list, select the Spotify connection.
  4. Enter https://api.spotify.com/v1/me/playlists for the URL field.
  5. Test the card or the flow.
Calling Spotify API.

Note: You need to have a playlist in your Spotify account.

Testing a flow with a call to Spotify API.

Behind the scenes

When you create a connection to Spotify, Okta Workflows will request an access token for you and make an API call that looks like this:

curl --request GET \
--url https://api.spotify.com/v1/me/playlists \
--header 'Authorization: Bearer <access_token>'

Okta Workflows will also automatically request a new token when the current token expires.

Okta Workflows resources

🍫 Get help from Workflows specialists during weekly community office hours.

πŸ“Ί Learn from Workflows videos.

πŸ›Ÿ Get help from support: discuss a Workflows topic or ask a question.

πŸ™‹πŸ»β€β™€οΈ Get help from the community: join the #okta-workflows channel on MacAdmins Slack.

Leave a comment