[GH-ISSUE #56] Song.like_song() raises SongError (GraphQL variable mismatch: uris vs libraryItemUris) #34

Closed
opened 2026-02-27 19:06:33 +03:00 by kerem · 1 comment
Owner

Originally created by @nogaemer on GitHub (Dec 25, 2025).
Original GitHub issue: https://github.com/Aran404/SpotAPI/issues/56

Hello,

I have written a little test script, that is supposed to like the currently playing song. The current problem I am facing is, that song.like_song(track_id) will raise spotapi.exceptions.errors.SongError: Could not like song.

Based on the error logs, it appears the library is sending the wrong variable name in the GraphQL payload. The API expects libraryItemUris but the library sends uris.

Environment:

  • OS: Windows
  • SpotAPI Version: 1.2.7

song.py line 278 :

"variables": {"uris": [f"spotify:track:{song_id}"]},

should be:

"variables": {"libraryItemUris": [f"spotify:track:{song_id}"]},

Code:

from spotapi import (
    Login,
    Config,
    NoopLogger,
    PrivatePlaylist,
    JSONSaver, Song, PlayerStatus
)

config = Config(
    logger=NoopLogger()
)

instance = Login.from_saver(JSONSaver(), cfg=config, identifier="*****************************")

playlist = (PrivatePlaylist(instance).get_library().get("data").get("me").get("libraryV3").get("items")[0]
            .get("item").get("_uri"))  ##uri of the liked songs playlist.

status = PlayerStatus(instance)
player = status.state

liked_songs_playlist = PrivatePlaylist(instance, playlist)
# liked_songs_playlist.create_playlist(name="test playlist") # Test if I am logged in -> playlist is created = logged in

track_uri = player.track.uri  # e.g. "spotify:track:3n3Ppam7vgaVa1iaRUc9Lp"
track_id = track_uri.split(":")[-1]  # -> "3n3Ppam7vgaVa1iaRUc9Lp"

song = Song(liked_songs_playlist)
song.like_song(track_id)

instance.save(JSONSaver())

Console error

Traceback (most recent call last):
  File "C:\Users\******\PycharmProjects\spotify_shortcuts\setup.py", line 28, in <module>
    song.like_song(track_id)
  File "C:\Users\******\PycharmProjects\spotify_shortcuts\.venv\Lib\site-packages\spotapi\types\annotations.py", line 47, in wrapper
    result: R = func(*args, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\******\PycharmProjects\spotify_shortcuts\.venv\Lib\site-packages\spotapi\song.py", line 290, in like_song
    raise SongError("Could not like song", error=resp.error.string)
spotapi.exceptions.errors.SongError: Could not like song

Payload that is sent to spotify

{
    "extensions": {
        "persistedQuery": {
            "sha256Hash": "7c5a69420e2bfae3da5cc4e14cbc8bb3f6090f80afc00ffc179177f19be3f33d",
            "version": 1
        }
    },
    "operationName": "addToLibrary",
    "variables": {
        "uris": [
            "spotify:track:0qcjuYtMWhBjXg0Xwt5SzS"
        ]
    }
}

###Error Object in song.py -> like_song() -> resp.error

Error(status_code=400, response={
    'errors': [
    {
        'message': 'missing variable `$libraryItemUris`: for required GraphQL type `[String!]!`', 'extensions': {
            'name': 'libraryItemUris',
            'code': 'VALIDATION_INVALID_TYPE_VARIABLE'
        }
    }]},
string="Status Code: 400, Response: {'errors': [{'message': 'missing variable `$libraryItemUris`: for required GraphQL type `[String!]!`', 'extensions': {'name': 'libraryItemUris', 'code': 'VALIDATION_INVALID_TYPE_VARIABLE'}}]}"
)
Originally created by @nogaemer on GitHub (Dec 25, 2025). Original GitHub issue: https://github.com/Aran404/SpotAPI/issues/56 Hello, I have written a little test script, that is supposed to like the currently playing song. The current problem I am facing is, that `song.like_song(track_id)` will raise spotapi.exceptions.errors.SongError: Could not like song. Based on the error logs, it appears the library is sending the wrong variable name in the GraphQL payload. The API expects `libraryItemUris` but the library sends `uris`. **Environment:** * **OS:** Windows * **SpotAPI Version:** 1.2.7 </br> song.py line 278 : ```python "variables": {"uris": [f"spotify:track:{song_id}"]}, ``` should be: ```python "variables": {"libraryItemUris": [f"spotify:track:{song_id}"]}, ``` <hr> ### Code: ```python from spotapi import ( Login, Config, NoopLogger, PrivatePlaylist, JSONSaver, Song, PlayerStatus ) config = Config( logger=NoopLogger() ) instance = Login.from_saver(JSONSaver(), cfg=config, identifier="*****************************") playlist = (PrivatePlaylist(instance).get_library().get("data").get("me").get("libraryV3").get("items")[0] .get("item").get("_uri")) ##uri of the liked songs playlist. status = PlayerStatus(instance) player = status.state liked_songs_playlist = PrivatePlaylist(instance, playlist) # liked_songs_playlist.create_playlist(name="test playlist") # Test if I am logged in -> playlist is created = logged in track_uri = player.track.uri # e.g. "spotify:track:3n3Ppam7vgaVa1iaRUc9Lp" track_id = track_uri.split(":")[-1] # -> "3n3Ppam7vgaVa1iaRUc9Lp" song = Song(liked_songs_playlist) song.like_song(track_id) instance.save(JSONSaver()) ``` ### Console error ``` Traceback (most recent call last): File "C:\Users\******\PycharmProjects\spotify_shortcuts\setup.py", line 28, in <module> song.like_song(track_id) File "C:\Users\******\PycharmProjects\spotify_shortcuts\.venv\Lib\site-packages\spotapi\types\annotations.py", line 47, in wrapper result: R = func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\******\PycharmProjects\spotify_shortcuts\.venv\Lib\site-packages\spotapi\song.py", line 290, in like_song raise SongError("Could not like song", error=resp.error.string) spotapi.exceptions.errors.SongError: Could not like song ``` ### Payload that is sent to spotify ```json { "extensions": { "persistedQuery": { "sha256Hash": "7c5a69420e2bfae3da5cc4e14cbc8bb3f6090f80afc00ffc179177f19be3f33d", "version": 1 } }, "operationName": "addToLibrary", "variables": { "uris": [ "spotify:track:0qcjuYtMWhBjXg0Xwt5SzS" ] } } ``` ###Error Object in song.py -> like_song() -> resp.error ```python Error(status_code=400, response={ 'errors': [ { 'message': 'missing variable `$libraryItemUris`: for required GraphQL type `[String!]!`', 'extensions': { 'name': 'libraryItemUris', 'code': 'VALIDATION_INVALID_TYPE_VARIABLE' } }]}, string="Status Code: 400, Response: {'errors': [{'message': 'missing variable `$libraryItemUris`: for required GraphQL type `[String!]!`', 'extensions': {'name': 'libraryItemUris', 'code': 'VALIDATION_INVALID_TYPE_VARIABLE'}}]}" ) ```
kerem closed this issue 2026-02-27 19:06:33 +03:00
Author
Owner

@nogaemer commented on GitHub (Dec 26, 2025):

#57

<!-- gh-comment-id:3692775775 --> @nogaemer commented on GitHub (Dec 26, 2025): #57
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SpotAPI#34
No description provided.