spotify / web-api

This issue tracker is no longer used. Join us in the Spotify for Developers forum for support with the Spotify Web API ➡️ https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer
981 stars 79 forks source link

Get artist names only from “Get a Playlist's Tracks” endpoint #891

Open davidmichaelhuber opened 6 years ago

davidmichaelhuber commented 6 years ago

Introduction

I am using this endpoint of the Spotify Web API. I am using the fields query parameter in order to solely request the data I am going to need.

Problem

Without any filtering the JSON returned from the API will contain an array called items. The first key in each object of items is called added_at. In order to receive this key only the fields parameter needs to be items(added_at).

There is another key in each object of items called track. Within track there is an array called artists. Each entry of artists has a key called name. So this should be the same situation as described in the second paragraph. Therefore I should get the names of the artists only by using items(track(artists(name))).

Actually this does always return the whole artists array. It seems like the (name) selector is ignored.

Example

The responses for items(added_at, track(artists)) & items(added_at, track(artists(name))) are actually the same and look like this:

{
  "items": [
    {
      "added_at": "2017-08-24T14:56:20Z",
      "track": {
        "artists": [
          {
            "external_urls": {
              "spotify": "https://open.spotify.com/artist/4V8Sr092TqfHkfAA5fXXqG"
            },
            "href": "https://api.spotify.com/v1/artists/4V8Sr092TqfHkfAA5fXXqG",
            "id": "4V8Sr092TqfHkfAA5fXXqG",
            "name": "Luis Fonsi",
            "type": "artist",
            "uri": "spotify:artist:4V8Sr092TqfHkfAA5fXXqG"
          },
          {
            "external_urls": {
              "spotify": "https://open.spotify.com/artist/4VMYDCV2IEDYJArk749S6m"
            },
            "href": "https://api.spotify.com/v1/artists/4VMYDCV2IEDYJArk749S6m",
            "id": "4VMYDCV2IEDYJArk749S6m",
            "name": "Daddy Yankee",
            "type": "artist",
            "uri": "spotify:artist:4VMYDCV2IEDYJArk749S6m"
          }
        ]
      }
    }
  ]
}

Question

So how can I filter the artists array to only show the name of the artists by using query parameters? Am I wrong about the assumption that items & added_at can be compared to artists & name and therefore the syntax I use is wrong or is there something else that I am missing?

Edits

stcalica commented 6 years ago

I have the same question as well. Seems like it doesn't have a syntax for arrays -__-

davidmichaelhuber commented 6 years ago

@stcalica Actually I think it supports arrays because items is one as well. But nested arrays get ignored somehow.

stcalica commented 6 years ago

Ah, I didn't realize that. Yes I believe it does ignore nested arrays. Hopefully they fix this, soonish :/

My workaround is just grabbing it as is and retrieving it in my own code.

christopherpow commented 6 years ago

I also have this issue. Any update?

davidmichaelhuber commented 6 years ago

I also have this issue. Any update?

Unfortunately I didn't dig into it any further.

matthewslaney commented 5 years ago

I'm having the same issue. My assumption is that this behavior is due to the fact that you can have multiple artists for one track. Therefore: track.artist.name maybe doesn't exist since it would really be: track.artists.artist.name

However, I tried a few iterations of field names and syntaxes and got nowhere.

tudorturcu commented 5 years ago

I'm having the same issue. I also think nested arrays are the problem, since items is an array.

mackorone commented 5 years ago

I'm hitting the same issue. Admittedly, it's not a huge deal, since I can just ignore the unrequested data. Still, it's kind of annoying. @rohansingh, do you know anyone who can look into this?

cdbattags commented 5 years ago

Same issue for me as well

pniedzwiedzinski commented 5 years ago

+1

aaanguyen commented 5 years ago

been at this for a while, would also appreciate a fix

aadibajpai commented 5 years ago

Add me to the list too.

George--V commented 5 years ago

Same issue here

bannmann commented 4 years ago

+1

umitao commented 4 years ago

I am able to pull every other field from API, but any selector in artists object. Track names, album names, popularity, duration... everything is ok, but artists. I'm going crazy. If I write {{items.0.track.artists}} I get an object return, but {{items.0.track.artists.name}} returns nothing. Did anyone face that before?

umitao commented 4 years ago

Figured from the same issue's Stackoverflow page. Just so if anyone has the same, if you type {{items.0.track.artists.0.name}} it works apparently I had to tell the index number again after artists object

matthewslaney commented 4 years ago

Correct, @umitao That follows what we've been saying, that it's a nested array. But this bug is specifically about not being able to tell the API to give you only that data. Since it's working for you, I'm assuming that means you got all the fields from the API and then filtered on the client side, right? I haven't played with this in a while, but if that query worked directly against the API this bug might have been fixed.

umitao commented 4 years ago

Actually I was playing with the web interface before I used it in code, and after looking again, I noticed the bug is still there. It returns all the artists' attributes even though I did not type it in the fields. I just coded it first time today and yes I am only printing artist name in HTML, so you are right and for sure the bug is still there.

umitao commented 4 years ago

What got me thinking is actually the index of the artists array. If I want to print artists name (or any other attribute), the index is always 0 : {{items.5.track.artists.0.name}} and {{items.5.track.artists.0.href}} I also later realized that artists object always returns every value in Simplified artist object.

kristinamongo commented 4 years ago

+1