Is the API failing?

I am a recent new developer, but I had my application working great just a couple of weeks ago.    Through the API, I had my application doing just about everything I wanted  (adjust volume, start a playlist, do previous and next track, pause, resume).   I took about 10 days off.  Now most things are not working.

 

It seems that my GET calls to the API work, but not PUTs.

Is anyone else having this problem?

Child Item
Child Item
Child Item

Accepted answers

Could you maybe provide the response body that you're receiving alongside the 404? Might help.

Well, the problem turned out to be that my speakers (Amazon Echo Devices) needed to be rebooted.  Once I did this, my code started working again.   Thank you all who made suggestions !!!

 

 

All comments

What does your code do? How do you get an Access token, an with which Scopes?

I don't remember which scopes I originally requested, but my application was working fully just 2 weeks ago.   Here are some clips from my code:

1. I am able to get the access token successfully

2. I am able to run GETs like get list of devices

3.  I am unable to run PUTs like set volume.   This worked two weeks ago.

 

Thank you for any help you can give me.

 

 

#*************************************************************************
# Get Spotify access token
#*************************************************************************
lUrl = f"https://accounts.spotify.com/api/token"
headers = {}
data = {}

# Encode as Base64
message = f"{gClientId}:{gClientSecret}"
messageBytes = message.encode('ascii')
base64Bytes = base64.b64encode(messageBytes)
base64Message = base64Bytes.decode('ascii')

headers['Authorization'] = f"Basic {base64Message}"

data['grant_type'] = "refresh_token"
data['refresh_token'] = gAuthorizationRefreshToken

res = requests.post(lUrl, headers=headers, data=data)

gToken = res.json()['access_token']


 


#*************************************************************************
# Get a list of devices
#*************************************************************************

lUrl = f"https://api.spotify.com/v1/me/player/devices"

headers = {
"Authorization": "Bearer " + gToken
}

res = requests.get(url=lUrl, headers=headers)
lres = json.dumps(res.json(), indent=2)

 

 

#*************************************************************************
# Set Volume
#*************************************************************************

print("Entered Volume Routine")

Volurl = f"https://api.spotify.com/v1/me/player/volume?volume_percent=" + str(ActionValue1) + "&device_id=" + gDevice

headers = {
"Authorization": "Bearer " + gToken
}

print(Volurl)
res = requests.put(url=Volurl, headers=headers)
print(res)

 

 

 

 

You can try to get a new token with the user-read-playback-state and user-modify-playback-state scopes.

Thank you.  I will try that.   

What is interesting is that I am not getting any kind of a security response.  I am getting a 404 error.   This made me think the API might have been down.

Could you maybe provide the response body that you're receiving alongside the 404? Might help.

Thank you for asking for the response body.  I was only looking at the status code 404.   Here is the full response:

{
"error": {
status": 404,
"message": "Device not found"
}
}

 

But what is odd is that I know I specified the correct device id.   I captured the api string:

https://api.spotify.com/v1/me/player/volume?volume_percent=25&device_id=ac7607375393d07737dd2741baca2a1fb0e28320

 

And that is a valid device on my system.    I can see it when I query for my devices and I have double and tripled checked to see that the device id is correct..   Any idea why the API would return invalid device?

 

 

 

 

 

Well, the problem turned out to be that my speakers (Amazon Echo Devices) needed to be rebooted.  Once I did this, my code started working again.   Thank you all who made suggestions !!!

 

 

Child Item
Child Item