DataGrip is a database IDE that allows SQL developers to query, create, and manage databases. When paired with the CData API Driver for JDBC, DataGrip can work with live Spotify data. This article shows how to establish a connection to Spotify data in DataGrip.
Create a New Driver Definition for Spotify
The steps below describe how to create a new Data Source in DataGrip for Spotify.
- In DataGrip, click File -> New > Project and name the project
π Creating a new DataGrip project.
- In the Database Explorer, click the plus icon () and select Driver.
π Adding a new Driver.
- In the Driver tab:
- Set Name to a user-friendly name (e.g. "CData Spotify Driver")
- Set Driver Files to the appropriate JAR file. To add the file, click the plus (), select "Add Files," navigate to the "lib" folder in the driver's installation directory and select the JAR file (e.g. cdata.jdbc.api.jar).
- Set Class to cdata.jdbc.api.API.jar
- Click "Apply" then "OK" to save the Connection
π A configured Driver (Salesforce is shown).
Configure a Connection to Spotify
- Once the connection is saved, click the plus (), then "Data Source" then "CData Spotify Driver" to create a new Spotify Data Source.
- In the new window, configure the connection to Spotify with a JDBC URL.
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the Spotify JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.api.jar
Fill in the connection properties and copy the connection string to the clipboard.
Using OAuth Authentication
Spotify uses OAuth 2.0 for authentication. You will need to create an application in the Spotify Developer Dashboard to obtain your client credentials.
Setting Up Your Spotify Application
- Visit the Spotify Developer Dashboard.
- Log in with your Spotify account and click Create app.
- Provide an app name, description, and set a Redirect URI (e.g.,
http://localhost:33333
for desktop applications).
- Copy your Client ID and Client Secret from the app settings.
Connection Properties
After setting the following connection properties, you are ready to connect:
- AuthScheme: Set this to OAuth.
- InitiateOAuth: Set this to GETANDREFRESH. You can use InitiateOAuth to manage the process to obtain the OAuthAccessToken.
- OAuthClientId: Set this to your Spotify application's Client ID.
- OAuthClientSecret: Set this to your Spotify application's Client Secret.
- Scope: Set this to the required OAuth scopes (space-separated). The default includes all read scopes needed for the tables in this profile.
- CallbackURL: Set this to the Redirect URI configured in your Spotify application (e.g., http://localhost:33333).
Example Connection String
Profile=C:\profiles\Spotify.apip;AuthScheme=OAuth;InitiateOAuth=GETANDREFRESH;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;CallbackURL=http://localhost:33333;
Available OAuth Scopes
- user-read-private: Read access to user's subscription details and explicit content settings.
- user-read-email: Read access to user's email address.
- user-library-read: Read access to a user's saved tracks, albums, episodes, shows, and audiobooks.
- playlist-read-private: Read access to user's private playlists.
- playlist-read-collaborative: Read access to collaborative playlists the user follows.
- user-follow-read: Read access to the list of artists the current user follows.
- user-read-playback-state: Read access to a user's player state (device, current track, progress).
- user-read-currently-playing: Read access to a user's currently playing content.
- user-read-playback-history: Read access to a user's recently played tracks.
- user-top-read: Read access to a user's top artists and tracks.
π Using the built-in connection string designer to generate a JDBC URL (Salesforce is shown.)
- Set URL to the connection string, e.g.,
jdbc:api:Profile=C:\profiles\Spotify.apip;AuthScheme=OAuth;InitiateOAuth=GETANDREFRESH;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;CallbackURL=http://localhost:33333;
- Click "Apply" and "OK" to save the connection string
π A configured Data Source (Salesforce is shown).
At this point, you will see the data source in the Data Explorer.
Execute SQL Queries Against Spotify
To browse through the Spotify entities (available as tables) accessible through the JDBC Driver, expand the Data Source.
π Exploring the data (Salesforce is shown.)
To execute queries, right click on any table and select "New" -> "Query Console."
π Opening a new Query Console.
In the Console, write the SQL query you wish to execute. For example:
SELECT , FROM Albums WHERE Id = '4aawyAB9vmqN3uQ7FjRGTy'
π Querying with SQL (Salesforce is shown.)
Download a free, 30-day trial of the CData API Driver for JDBC and start working with your live Spotify data in DataGrip. Reach out to our Support Team if you have any questions.