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

ParameterRequiredDescription
playlistidYesThe ID of the Spotify playlist.
tokenYesA valid authorization token for accessing spotify2pdf API.

How to generate a token ?

Subscription API Plan

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

ParameterTypeDescription
codeintA status code representing whether the request was successful or failed.
data.filestringThe filepath of the PDF file that was generated.
messagestringA 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());
            }
        }
    }
}