Spotify Get Search Token (Utility)
This utility shortcut obtains a new search token from the Spotify API
Description
This shortcut is an easy way to obtain a new search token from the Spotify API. The token is needed to authorize search queries. It lasts for one hour.
The shortcut tries to read both your Spotify client id and client secret from a dictionary named spotifyApi inside your DataJar application. These values are needed to obtain a search token. After successful retrieval, the search token will automatically be written into your DataJar dictionary and can then be used and reused inside all your Spotify search shortcuts.
The following steps need to be done in order to make this shortcut work:
-
Create a new app and get your client id and client secret from the Spotify Developer Dashboard
-
Open DataJar, create a new dictionary named spotifyApi and put both your client id and client secret inside:
- spotify client id has to be named clientId (type: Text)
- spotify client secret has to be named clientSecret (type: Text)
That's it. I'm using this shortcut in all my other Spotify shortcuts which need a valid search token. Just make the API request by using the current token spotifyApi.searchToken from DataJar. If the "Get contents of URL" call returns an error with http state 401 (unauthorized), just call this shortcut once and afterwards call your own shortcut again. This time it will work (and return http 200 Success).
To summarize: This shortcut is meant as a Spotify utility to obtain a valid search token. The token is stored in DataJar and can be reused all the time as long as it's valid. This saves you time coding your shortcuts, it saves unneeded http api requests and it makes your shortcuts run faster.