Is there a way to clear the sonos queue via the API?

308 Views Asked by At

I'm trying to create a system that will shuffle a favorited playlist at command.

So far the flow looks somthing like this:

  1. /households/{household_id}/groups/createGroup
{'playerIds': [player_id]}
  1. /groups/{group_id}/favorites
{'playOnCompletion': True,
'favoriteId': album_id,
  "playModes": {
"shuffle": True,
},
'queueAction': 'REPLACE'}

This however seems to only add the songs to the queue THEN shuffle, meaning that its hit or miss whether or not the next song is even from the correct album.

I have figured out that if I clear the queue manually first it works fine. I generally want the behavior of pressing shuffle in the sonos app, where it clears the queue and just plays what you just clicked.

Any ideas?

1

There are 1 best solutions below

0
Joshua On

Solved! As it turns out, the sonos documentation is just plain wrong, instead of specifying a queueAction, you need to specify an action.

For example instead of:

{'playOnCompletion': True,
'favoriteId': album_id,
"playModes": {
  "shuffle": True,
},
'queueAction': 'REPLACE'
}

You would need:

{'playOnCompletion': True,
'favoriteId': album_id,
"playModes": {
  "shuffle": True,
},
'action': 'replace'
}

It's pretty subtle but took me ages to solve.

Hope this helps somebody.