Convert Your Spotify Song PlayList to PDF Printer Art With Nodejs & Java
Request
BaseAPIUrl
https://api.sharegiftlist.com/api/v3
Endpoint
/spotify2pdf
Method
POST
Request Body
Parameter | Required | Description |
---|---|---|
playlistid | Yes | The ID of the Spotify playlist. |
token | Yes | A valid authorization token for accessing spotify2pdf API. |
How to generate a token ?
Query Parameters
None
Response
Success Response
{
"code": 0,
"data": {
"file": "pdf/2023-06-06/XBnqRkiVIIZmKksTeVay.pdf"
},
"message": "success"
}
Error Response
In case of an error, the API returns a JSON object with an error message.
{
"code": 1,
"message": "<error_message>"
}
Response Parameters
Parameter | Type | Description |
---|---|---|
code | int | A status code representing whether the request was successful or failed. |
data.file | string | The filepath of the PDF file that was generated. |
message | string | A message indicating whether or not the request was successful. |
Example Code
Node.js
const axios = require('axios');
const token = "sk-xxxxx"; //
const playlistid = "3InUX2j1yB7A1u2ZhUNHgX";
const baseDownloadUrl = "https://api.sharegiftlist.com/download/"
const baseApiUrl = "https://api.sharegiftlist.com/api/v3"
// const baseApiUrl = "http://localhost:9092/api/v3"
const req = {
playlistid: playlistid,
token: token
}
axios.post(baseApiUrl +'/spotify2pdf', req)
.then(response => {
if (response.data.code == 0) {
//download url
console.log("download url ", baseDownloadUrl + response.data.data.file)
} else {
console.log(response.data);
}
})
.catch(error => {
console.log(error.response.data);
});
Java
import java.io.IOException;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.Request;
import okhttp3.Response;
public class Spotify2PdfExample {
public static void main(String[] args) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
String token = "sk-xxxxx";
String playlistid = "3InUX2j1yB7A1u2ZhUNHgX";
String baseDownloadUrl = "https://api.sharegiftlist.com/download/";
String baseApiUrl = "https://api.sharegiftlist.com/api/v3";
// String baseApiUrl = "http://localhost:9092/api/v3";
RequestBody body = RequestBody.create(
MediaType.parse("application/json"),
"{\"playlistid\":\"" + playlistid + "\",\"token\":\"" + token + "\"}");
Request request = new Request.Builder()
.url(baseApiUrl + "/spotify2pdf")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
String responseBody = response.body().string();
System.out.println(responseBody);
// Parse the response JSON and get the download URL
JsonObject jsonResponse = JsonParser.parseString(responseBody).getAsJsonObject();
if (jsonResponse.get("code").getAsInt() == 0) {
String downloadUrl = baseDownloadUrl + jsonResponse.get("data").getAsJsonObject().get("file").getAsString();
System.out.println("Download URL: " + downloadUrl);
} else {
System.out.println("Error: " + jsonResponse.get("message").getAsString());
}
}
}
}