Music is an essential part of life for millions of music lovers all over the world. While some people prefer to listen to music at leisure, for others it is a hobby to be indulged in while commuting, exercising, or even cooking a meal. The advent of the internet has given rise to what is known as on-demand music streaming services and an increasing number of users are shifting to such platforms to listen to their favorite tracks. Not only do such platforms make millions of songs available at users’ fingertips, but they make listening to music very easy and convenient. Most such online music streaming platforms offer REST APIs that expose their data. Once such API is the Deezer API. In this article, we will be learning about this API and its features.
What is the Deezer API
Deezer is a very popular music streaming service. It has an extensive collection of soundtracks from various artists across the globe. It provides features like music discovery, mood-based music, personalized music recommendations, the ability to create playlists, and much more. It is available on various platforms like Windows, Android, and iOS.
The Deezer API is a REST API for Deezer. It provides REST endpoints that expose Deezer data. So, for example, it provides endpoints that allow searching for soundtracks, obtaining information about a track, obtaining information about an album, and so forth.
Who is the Deezer API for?
The Deezer API can typically be used by developers working on music, entertainment, social media, and news applications. Such developers can use the Deezer API endpoints to provide music-related services to their users through mobile/web/desktop applications.
Secondly, the Deezer API can be used by music artists. Such users can leverage the API endpoints to obtain competitors’ information and/or gain an insight into the type of music content available on Deezer.
Next, the Deezer API can be used by music bloggers. Such users can utilize the API endpoints to obtain information about artists, albums, playlists, etc. This information can be used to create exciting blog content.
Finally, the Deezer API can be used by individuals for educational purposes. Since the API is completely free, such users can use the API to learn how REST APIs work.
How does the Deezer API work?
The Deezer API is a REST API and works on REST principles. In brief, REST is a client-server architecture style. It consists of a server-side REST service (that provides some functionality) and a client-side REST client (that consumes the service). The REST service exposes services in the form of REST endpoints. A REST endpoint is nothing but an HTTP URL. A REST client (also known as a client application) can consume the endpoint by specifying its URL. Along with the URL, a client application may optionally need to supply request parameters (values required by an endpoint to process a request) and authentication headers (information required to validate the client). The endpoint then processes the request and returns data corresponding to the request. The data returned is typically in JSON format.
The Deezer API works on the same principles. It exposes several endpoints that provide information about artists, albums, playlists, etc. A client application can query an endpoint by supplying the endpoint URL, authentication headers (RapidAPI key and RapidAPI host), and request parameters (if any). The endpoint then processes the request and returns the desired information.
How to use the Deezer API?
You can use RapidAPI to connect to the Deezer API. Not only does RapidAPI list all of the Deezer API endpoints, but it also provides code snippets in popular programming languages. These can be used by an application developer as required. Further, it also allows executing an API endpoint from the browser itself. So, developers can test the endpoints without writing any code.
To use RapidAPI to connect to Deezer API, you need to follow the steps given below.
Step 1 – Signing Up
The first step is to create a RapidAPI account as described below.
a. Enter the Deezer RapidAPI URL (https://rapidapi.com/deezerdevs/api/deezer-1/) in a browser. Click on the Log In/Sign Up button in the top right corner. This redirects to the following authentication page:
b. Authenticate yourself using any of the methods shown on the page. I will choose to log in with Google. Upon successful authentication, the following page is displayed. All the available API endpoints are displayed on the left:
Step 2 – Executing an endpoint
As mentioned earlier, RapidAPI allows executing an endpoint from the browser and viewing its response. To execute an endpoint, you need to do the following:
a. Click on the desired endpoint from the endpoints list on the left. I have selected the search endpoint. Click the Test Endpoint button:
b. View the Response in the Results tab:
Step 3 – Obtaining a code snippet
As explained earlier, the Deezer API is a REST API and can be invoked by application code written in any programming language. Since a REST API exposes its endpoints as HTTP URLs, a programming language-specific HTTP client library needs to be used to invoke an API endpoint. Most programming languages support multiple HTTP libraries. Not only does RapidAPI provides code snippets in various programming languages, but it provides code for multiple HTTP libraries in each programming language. Thus, developers can obtain code in the programming language/HTTP library of their choice.
For example, to obtain a code snippet in C#, you need to do the following:
a. Click on the desired endpoint from the endpoints list on the left. I have selected the search endpoint. In the code snippets tab, Click on C# -> RestSharp:
b. Copy the C# code shown and use it as desired:
Deezer API EndPoints
Let us now take a detailed look at the Deezer API endpoints.
Radio
The radio endpoint provides information about a radio station. It accepts a single parameter called id. This is a mandatory parameter of type String that specifies the Deezer id of the radio station whose information is required. The JSON object returned contains information about the specified radio station like radio station title, radio station description links to the radio station images, etc.
Infos
The infos endpoint returns information about the API in the current country. It does not accept any parameters. The JSON object returned contains information like the country name, country code, etc.
Editorial
The editorial endpoint returns information about an editorial playlist. It accepts a single parameter called id. This is a mandatory parameter of type String that specifies the Deezer id of the editorial whose information is required. The JSON object returned information like the editorial playlist title, description, links to the playlist images, etc.
Track
The track endpoint provides information about a music track. It accepts a single parameter called id. This is a mandatory parameter of type String that specifies the Deezer id of the track whose information is required. The JSON object returned contains information about the track like the track title, duration, release date, etc. In addition, it also contains information about the track artist and album.
Artist
The artist endpoint provides information about a music artist. It accepts a single parameter called id. This is a mandatory parameter of type String that specifies the Deezer id of the artist whose information is required. The JSON object returned contains information about the artist like the artist’s name, link to the artist’s profile, link to the artist’s picture, etc.
Playlist
The playlist endpoint provides information about a music playlist. It accepts a single parameter called id. This is a mandatory parameter of type String that specifies the Deezer id of the playlist whose information is required. The JSON object returned contains information about the playlist like the playlist title, playlist description, links to the playlist images, etc.
Search
The search endpoint helps to search for tracks based on a search String. It accepts a single parameter called q. This is a mandatory parameter of type String that specifies the text to be searched. The JSON object returned contains a list of objects. Each object in the list corresponds to a track that matches the search string. It includes information about the track like the track title, duration, artist information, album information, etc.
Genre
The genre endpoint provides information about a genre. It accepts a single parameter called id. This is a mandatory parameter of type String that specifies the Deezer id of the genre whose information is required. The JSON object returned contains information like the genre name, links to the genre images, etc.
Comment
The comment endpoint provides information about an artist’s comment. It accepts a single parameter called id. This is a mandatory parameter of type String that specifies the Deezer id of the comment whose information is required. The JSON object returned contains information like the comment title, etc.
Album
The album endpoint provides information about a music album. It accepts a single parameter called id. This is a mandatory parameter of type String that specifies the Deezer id of the album whose information is required. The JSON object returned contains information like the album title, duration, release date, label, artist information, etc.
How to use the Deezer API with various programming languages
As explained earlier, RapidAPI provides code snippets for executing the API endpoints in several popular programming languages. Some of the programming languages supported by RapidAPI are Java, Python, PHP, Ruby, NodeJS. In addition, RapidAPI supports multiple HTTP client libraries in each programming language. Let us take a look at a few code samples.
Using the Deezer API with Java
In order to use the Deezer API with Java, click the desired API endpoint on the left. In the code snippets tab, select “Java” and the desired HTTP client library. Copy the code snippet and use it as required.
For example, RapidAPI provides the following Java code for the Radio endpoint using the OkHttp library:
OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://deezerdevs-deezer.p.rapidapi.com/radio/%7Bid%7D") .get() .addHeader("x-rapidapi-host", "<your host here>") .addHeader("x-rapidapi-key", "<your key here>") .build(); Response response = client.newCall(request).execute();
Using the Deezer API with Python
In order to use the Deezer API with Python, click the desired API endpoint on the left. In the code snippets tab, select “Python” and the desired HTTP client library. Copy the code snippet and use it as required.
For example, RapidAPI provides the following Python code to execute the Infos endpoint using the Unirest library:
import http.client conn = http.client.HTTPSConnection("deezerdevs-deezer.p.rapidapi.com") headers = { 'x-rapidapi-host': "<your host here>", 'x-rapidapi-key': "<your key here>" } conn.request("GET", "/infos", headers=headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
Using the Deezer API with PHP
In order to use the Deezer API with PHP, click the desired API endpoint on the left. In the code snippets tab, select “PHP” and the desired HTTP client library. Copy the code snippet and use it as required.
For example, RapidAPI provides the following PHP code to execute the Editorial endpoint using the cURL library:
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://deezerdevs-deezer.p.rapidapi.com/editorial/119606", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: <your host here>", "x-rapidapi-key: <your key here>" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
Using the Deezer API with Ruby
In order to use the Deezer API with Ruby, click the desired API endpoint on the left. In the code snippets tab, select “Ruby” and the desired HTTP client library. Copy the code snippet and use it as required.
For example, RapidAPI provides the following Ruby code to execute the Track endpoint using the net::http library:
require 'uri' require 'net/http' require 'openssl' url = URI("https://deezerdevs-deezer.p.rapidapi.com/track/1109731") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = '<your host here>' request["x-rapidapi-key"] = '<your key here>' response = http.request(request) puts response.read_body
Using the Deezer API with Javascript
In order to use the Deezer API with Javascript, click the desired API endpoint on the left. In the code snippets tab, select “Javascript” and the desired HTTP client library. Copy the code snippet and use it as required.
For example, RapidAPI provides the following Javascript code to execute the Artist endpoint using the fetch library:
fetch("https://deezerdevs-deezer.p.rapidapi.com/artist/13", { "method": "GET", "headers": { "x-rapidapi-host": "<your host here>", "x-rapidapi-key": "<your key here>" } }) .then(response => { console.log(response); }) .catch(err => { console.error(err); });
In addition, RapidAPI also provides code snippets in other programming languages like Node.js, C, Kotlin, Swift, etc. which can be obtained via the code snippets tab.
What are the benefits of the Deezer API?
Free – The most important benefit of the Deezer API is that it is completely free. This makes the API extremely suitable for developers/organizations looking for an economically viable music API.
Simple – Another important benefit of the Deezer API is that it is simple and easy to use. All the API endpoints are straightforward. Moreover, the endpoints accept very few parameters that are self-explanatory.
Comprehensive Data – Finally, the Deezer API provides comprehensive data. It has information about millions of music tracks, thousands of artists/albums/playlists across several genres. This makes the API an excellent choice for anyone looking for extensive music information.
Other Music APIs
Like the Deezer API, there are several other music APIs available on RapidAPI. Let us take a look at some of the other music APIs.
- SoundCloud API – Like Deezer, SoundCloud is a popular music streaming platform. The SoundCloud API exposes SoundCloud data. So, it provides various endpoints that provide data related to music tracks, artists, albums, etc. Further, it also provides endpoints that allow updating/uploading tracks, updating playlists, etc.
- AudioDB API – AudioDB is a community-driven database of music data that includes audio metadata related to songs, artists, and albums. The AudioDB API is a REST API that exposes AudioDB data. It includes various endpoints that return artist, track, album, playlist information.
- Shazam API – Shazam is a popular music recognition application. The Shazam API is an API for Shazam. It provides various endpoints that allow searching for songs, identifying a song based on its base64 encoded byte array, listing top charts, listing top songs in a chart, and so on.
- The Billboard API – The BillBoard API provides the Billboard chart rankings. It includes various endpoints that return the artist 100 chart information, the billboard 200 chart information, etc.
- Spotify API – Spotify is a popular music platform that allows users to play music, create and save playlists, follow artists, and much more. The Spotify API is a REST API for Spotify. It provides endpoints for fetching data from the Spotify music catalog, managing user’s playlists/saved music data, etc.
Summary
So, to summarize, Deezer is a popular music streaming platform. The Deezer API is a REST API that exposes Deezer data. It provides various endpoints that allow retrieving information about a music track, artist, album, playlist, genre, and much more. In this article, we learned how to use RapidAPI to connect to the Deezer API and execute its endpoints. We also learned about all the endpoints that this API provides, the benefits of this API, and other alternate APIs in the music arena. Finally, we saw to use RapidAPI to obtain code snippets to execute the API endpoints in different programming languages.
Leave a Reply