Announcements
From 28th September 2026, Community private messages will no longer be available. If you have any private messages you'd like to keep, please save or copy them using these steps before this date. Thank you.

Help Wizard

Step 1

NEXT STEP

Track not being fetched - 404 error

Track not being fetched - 404 error

Plan

Premium

Country

Argentina

Device

(iPhone 8, Samsung Galaxy 9, Macbook Pro late 2016)

Operating System

Windows 10

 

My Question or Issue

I'm trying to make a GET request to the Spotify Web API for a track using simple JavaScript (I don't know curl), but it's giving me a 404 error

My code:

//async function to get the token
const getToken = async() => {
    const result = await fetch('https://accounts.spotify.com/api/token', {
    method: 'POST',
    body: 'grant_type=client_credentials',
    headers: {
        'Authorization': 'Basic ' + Buffer.from(clientID + ':' + clientSecret).toString('base64'),
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    })
    const data = await result.json();
    const realToken = data.access_token;
    return realToken;
   
}
getToken().then((token) => {
    //async function to get songs
const getTracks = async(whatever) => {
    const result = await fetch('https://api.spotify.com/v1/track/6ydEhrdfzhI29D2NBAqUY1', {
        method: 'GET',
        headers: {
        'Authorization': 'Bearer ' + whatever,
        'Content-Type': 'application/json'
    }
    });
    const data = await result.json();
    return data;
}
getTracks(token);

});

 

 

Reply
0 Replies

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 5 years ago  in Social & Random