You can translate the document:

Introduction

The Spotify Web API endpoints return JSON metadata about music artists, albums, and tracks, directly from the Spotify Data Catalog. The Web API also provides access to user related data, like playlists and music that the user saves in the Your Music library.

In this document we will explain how to integrate this API in Denodo and how to configure its pagination.

Accessing the API

Integration with Denodo

Data source

The Spotify API is a REST API and returns responses in JSON format. So the first step is to create a JSON data source. To create the JSON data source, click on the Server Explorer go to New > Data source > JSON and introduce the following information:

  1. Data route: HTTP client.
  2. Base URL: https://api.spotify.com/v1/search?q=@query&type=track

In our example, we are accessing track's information, introducing a query in the parameter q.

Authentication

The Spotify API uses OAuth 2.0 authentication, to configure this type of authentication we need to create an app in Spotify first. Once it is created, we can get the client ID and the Client secret to configure the access from Denodo.

Also, in the app settings we have to establish the redirect uri of Denodo in our app:

After getting the client credentials and establishing the URI, from the Denodo Design Studio, go to the authentication section of the data source. Select “OAuth 2.0” authentication and introduce the client ID and the client secret obtained from the Spotify app. After doing this, click on “Launch the OAuth 2.0 credentials wizards to help you obtain those credentials”.

Enter the following information and follow these steps:

  1. Token endpoint URL: https://accounts.spotify.com/api/token
  2. Authorization server URL: https://accounts.spotify.com/authorize.
  3. Click on “Generate”. It will generate a URL which we have to copy, by clicking on “Open URL” we can see the whole URL.
  4. Paste the URL in section 3.
  5. Finally, click on “OAuth 2.0 credentials” and the authentication configuration will be completed.

Pagination

The Spotify API method that returns the track information includes the field next in the first response with the URL to the next page. The following responses will include the field next and in field previous, with the links to the next page and the previous page of results. By default there is a limit of 20 items per request and an offset of 0.  To configure this type of pagination in Denodo follow these steps:

  1. In the data source configuration go to the Pagination section.
  2. Introduce a maximum number of requests. In our case we are introducing 2 requests.

As we see in the screenshot below of the spotify API response, we can see that the URL of the next page is in the field next and the path to that field is tracks/next.

For configuring the pagination check “Obtain the next page URL from the response”. There, we need to indicate that the link to the next page is in the field next introducing the URL: tracks/next

Base view

Once we have created the data source we have to create a base view to retrieve information about the products of our store.

  1. We create a base view from the data source.
  2. Click on “OK”. And use the default tuple route. We will flatten the base view later instead of doing it at data source level because the tracks element also includes the next attribute that is needed for the pagination.

Final result

In order to select the fields and flatten the items that we want to retrieve from track information, we can create a flatten selection view from the base view.

  1. Right click on the base view and go to New > Flatten. There, click on the items field to flatten the array.

  1. In our example we are going to remove from the output some fields that we are not interested in. You can select the fields in the output section and there you check in the field that you want to remove and finally click on “Remove”. We have selected the fields shown in the screenshot below.

If we execute this new view with the query “miles davis”, we can see the following information: the query, the type, the uri of the track, the track ID, the duration of the track in ms and the name of the track. In the screenshot we can see 40 rows, that is because we had configured 2 requests with a limit of 20 tracks per request.

References

Search for Item - Spotify API

API token - Spotify API

Obtain the “Next Page URL” from the Body of the Response

Questions

Ask a question

You must sign in to ask a question. If you do not have an account, you can register here