spotify-web-api-node
spotify-web-api-node copied to clipboard
Add missing get Queue API Endpoint
Here is a new API Endpoint in current Spotify's API Docs: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-queue
I added it to the Lib.
In the mean-time for others who are waiting for this PR to be merged, you could also use the default node https
module to make the request:
import https from "https";
import SpotifyWebApi from "spotify-web-api-node";
type MyQueueResponse = {
currently_playing: SpotifyApi.TrackObjectFull | null;
queue: SpotifyApi.TrackObjectFull[];
};
// TODO wait for: https://github.com/thelinmichael/spotify-web-api-node/pull/465
export const getMyQueue = async (
accessToken: string,
attempt = 0
): Promise<MyQueueResponse> => {
const request = https.get({
hostname: "api.spotify.com",
path: "/v1/me/player/queue",
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
});
try {
return new Promise((resolve, reject) => {
let data = "";
request
.on("response", (response) => {
if (response.statusCode !== 200) reject(response.statusCode);
response.resume();
response.on("data", (chunk) => (data += chunk));
response.on("end", () => resolve(JSON.parse(data) as ClearQueueResponse));
})
.on("end", reject)
.on("error", reject);
});
} catch (error) {
console.error(`${getMyQueue.name}(${attempt}): ${JSON.stringify(error)}`);
}
};