Announcements

Help Wizard

Step 1

NEXT STEP

How to exclude fields from the results of a Web API call

How to exclude fields from the results of a Web API call

I want to pull just the artist name and track name using the "https://api.spotify.com/v1/playlists/{playlist_id}/tracks" call. The documentation says "Fields can be excluded by prefixing them with an exclamation mark", so I've tried to narrow down the results to just the two name fields. But no syntax I try with "!" seems to work.  As an example, I thought "&fields=items(track(album(artists(name,!href)),name))" would exclude "href", but it returns 400 ""Error parsing parameter: fields".  What am I misunderstanding?

Reply
3 Replies

Hey there, help's here!

Hmm, could you try to use this syntax: "fields=tracks.items(track(name,href,album(name,!href)))"? (tracks.items instead of 'items') Let me know if that helps here!

Have a great day!
Hubo
HuboSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Thank you for the help. Unfortunately, it didn't change anything.

 

Here's a more complete example, so maybe you'll see something else. (I wasn't completely sure which IDs are public and which ones are private, so I've replaced them all by <ID>.)

 

First, a working example and one of the results:

 

curl -X "GET" "https://api.spotify.com/v1/playlists/<ID>/tracks?offset=0&limit=100&fields=items(track(album(artists(name)),name))" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer <TOKEN>"

{
    "track" : {
      "album" : {
        "artists" : [ {
          "external_urls" : {
            "spotify" : "https://open.spotify.com/artist/<id>"
          },
          "href" : "https://api.spotify.com/v1/artists/<id>",
          "id" : "<id>",
          "name" : "Volbeat",
          "type" : "artist",
          "uri" : "spotify:artist:<id>"
        } ]
      },
      "name" : "Lola Montez"
    }
  },

 

 

Since I don't want external_urls, href, etc., I tried adding "!href" as a test. But it failed as below.

 

curl -X "GET" "https://api.spotify.com/v1/playlists/<ID>/tracks?offset=0&limit=100&fields=items(track(album(artists(name,!href)),name))" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer <TOKEN>"

{
  "error" : {
    "status" : 400,
    "message" : "Error parsing parameter: fields"
  }
}

 

 

Use this syntax:
 
curl --location --request GET 'https://api.spotify.com/v1/playlists/<playlist id>/tracks?fields=items(track(artists(name),name))' --header 'Authorization: Bearer <token>

Suggested posts