Announcements

Help Wizard

Step 1

NEXT STEP

403 Error - Get User's Top Items

403 Error - Get User's Top Items

I'm trying to retrieve user's top items from the API but getting a 403 error, other API calls to Spotify are working so my authentication seems fine, my scope is consistent with the documentation.

 

Below is a code screenshot and an example error, does anyone know what I'm doing wrong?

 

 

 

 

 

async function getUsersTopItems() {
    console.log("access token in function: ", access_token);
    let headerParameters = {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
        Authorization: "Bearer " + access_token,
      },
    };

    console.log("header params: ", headerParameters);

    try {
      const response = await fetch(
        "https://api.spotify.com/v1/me/top/artists",
        headerParameters
      );

      console.log("response: ", response);

      if (!response.ok) {
        const errorData = await response.json();
        console.error("API request failed with status:", response.status);
        console.error("Error details:", errorData);
        return;
      }

      const data = await response.json();
      console.log("artist data: ", data);
      console.log("artistID: ", artistID);
    } catch (error) {
      console.error("Error fetching data:", error);
    }
  }

 

 

 

 

delarue_0-1695099563730.png

 

Reply
3 Replies

Which endpoints do work, and did you get an Access Token with the right scopes?

Searching for artists is an example of one that works.

I get an access token back, I didn't see the scopes returned but I will
check later.

The code yiu are using you've got through the Client Credentials Flow. "Since this flow does not include authorization, only endpoints that do not access user information can be accessed."

You should choose another way of Authorization that lets you login and get an access token.

Suggested posts