From 9315d0099012ba66cce2e6a8b1fb8d1e21a890e7 Mon Sep 17 00:00:00 2001 From: Peter-Schorn <58197311+Peter-Schorn@users.noreply.github.com> Date: Thu, 12 Mar 2020 19:58:04 -0500 Subject: [PATCH] 'add to queue' endpoint added (#452) --- spotipy/client.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spotipy/client.py b/spotipy/client.py index e4127a8..8f114a0 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -1291,6 +1291,30 @@ class Spotify(object): ) ) + def add_to_queue(self, uri, device_id=None): + """ Adds a song to the end of a user's queue + + If device A is currently playing music and you try to add to the queue + and pass in the id for device B, you will get a + 'Player command failed: Restriction violated' error + I therefore reccomend leaving device_id as None so that the active device is targeted + + :param uri: song uri, id, or url + :param device_id: + the id of a Spotify device. + If None, then the active device is used. + + """ + + uri = self._get_uri("track", uri) + + endpoint = "me/player/queue?uri=%s" % uri + + if device_id is not None: + endpoint += "&device_id=%s" % device_id + + return self._post(endpoint) + def _append_device_id(self, path, device_id): """ Append device ID to API path.