Get user's playlists API bug

Solved!
Reply
Highlighted

Get user's playlists API bug

Casual Listener

Plan

Free

Country

Ukraine

Device

MacBookPro Retina, on Chrome

Operating System

(iOS )

 

My Question or Issue:

 

Hi, guys! I'm a developer building a non-commercial ReactJs app to showcase my skills of working with APIs and AJAX requests. 

Here's the problem I encountered:

One of my functions make a call to 

GET https://api.spotify.com/v1/users/{user_id}/playlists

in order to get the list of playlists, a user has in Spotify.

While the second call to the same endpoint returns the correct list of playlists, the first call always returns the same JSON consisting of 2 playlists, which aren't actually in the user's library (I checked this bug with 2 accounts currently and had the same outcome every time). Here is the JSON I get :

  1. (2) [{…}, {…}]
    1. 0:
      1. collaborative: false
      2. description: ""
      3. external_urls: {spotify: "https://open.spotify.com/playlist/1Wjl5nNjiOZJDAuHBvSDIe"}
      4. href: "https://api.spotify.com/v1/playlists/1Wjl5nNjiOZJDAuHBvSDIe"
      5. id: "1Wjl5nNjiOZJDAuHBvSDIe"
      6. images: (3) [{…}, {…}, {…}]
      7. name: "nirvana prefes"
      8. owner: {display_name: "undefined", external_urls: {…}, href: "https://api.spotify.com/v1/users/undefined", id: "undefined", type: "user", …}
      9. primary_color: null
      10. public: true
      11. snapshot_id: "MTMsZjUxMmZjMDg4ODIyYTAyNjZmZjJhNTNmY2JhMmUyOGNhYzc1M2JkNQ=="
      12. tracks: {href: "https://api.spotify.com/v1/playlists/1Wjl5nNjiOZJDAuHBvSDIe/tracks", total: 10}
      13. type: "playlist"
      14. uri: "spotify:playlist:1Wjl5nNjiOZJDAuHBvSDIe"
      15. __proto__: Object
    2. 1:
      1. collaborative: false
      2. description: ""
      3. external_urls: {spotify: "https://open.spotify.com/playlist/3zi6HOncBZUIlB0bikQ9YD"}
      4. href: "https://api.spotify.com/v1/playlists/3zi6HOncBZUIlB0bikQ9YD"
      5. id: "3zi6HOncBZUIlB0bikQ9YD"
      6. images: (3) [{…}, {…}, {…}]
      7. name: "Keep Calm"
      8. owner: {display_name: "undefined", external_urls: {…}, href: "https://api.spotify.com/v1/users/undefined", id: "undefined", type: "user", …}
      9. primary_color: null
      10. public: true
      11. snapshot_id: "NjMsODQ2NDljZThkZDIwNzM2OTJmMjA0M2EwMDNjOTAzNzQ2MTQxNmYwMw=="
      12. tracks: {href: "https://api.spotify.com/v1/playlists/3zi6HOncBZUIlB0bikQ9YD/tracks", total: 57}
      13. type: "playlist"
      14. uri: "spotify:playlist:3zi6HOncBZUIlB0bikQ9YD"
      15. __proto__: Object
    3. length: 2
    4. __proto__: Array(0)

So, I've got nothing agains nirvana or keeping Calm, but I can't keep calm while my app is not working correctly 😃

Please help me out. Thanks in advance!

 

 

PS the function is: 

 

async getUserPlaylists() {
const accessToken = this.getAccessToken();
const headers = {
Authorization: `Bearer ${accessToken}`,
};
const userID = await this.getCurrentUserId(); //GET current user’s ID
//Get a list of the playlists owned or followed by a Spotify user.

return fetch(`${spotifyLink}users/${userID}/playlists`, {
headers: headers,
})
.then((response) => {
return response.json();
})
.then((jsonResponse) => {
if (jsonResponse.items) {
console.log(jsonResponse.items);
return jsonResponse.items.map((playlist) => ({
id: playlist.id,
name: playlist.name,
}));
} else {
return [];
}
});
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Solution!

Re: Get user's playlists API bug

Spotify
Spotify

Welcome to the forum, @Siriakivska. Have you checked that the {user_id} is correct when your app calls https://api.spotify.com/v1/users/{user_id}/playlists?

View solution in original post

2 Replies
Highlighted
Solution!

Re: Get user's playlists API bug

Spotify
Spotify

Welcome to the forum, @Siriakivska. Have you checked that the {user_id} is correct when your app calls https://api.spotify.com/v1/users/{user_id}/playlists?

View solution in original post

Highlighted

Re: Get user's playlists API bug

Casual Listener

Hi, spotifyjosh,

Thanks a lot 

that may seem an easy one, and I was sure I checked it like 10 times before .

however when I double-checked again it turned out you were right !!

SUGGESTED POSTS