rinukkusu / spotify-dart

A dart library for interfacing with the Spotify API.
BSD 3-Clause "New" or "Revised" License
191 stars 91 forks source link

startOrResume throws error code 400 (malformed json) #185

Closed adamkoch closed 3 months ago

adamkoch commented 7 months ago

When I call startOrResume() I am getting error 400:

flutter: Error Code: 400
Malformed json
flutter: 
#0      SpotifyApiBase.handleErrors (package:spotify/src/spotify_base.dart:238:7)
#1      SpotifyApiBase._requestWrapper (package:spotify/src/spotify_base.dart:212:16)
<asynchronous suspension>
#2      SpotifyApiBase._putImpl (package:spotify/src/spotify_base.dart:201:12)
<asynchronous suspension>
#3      PlayerEndpoint.startOrResume (package:spotify/src/endpoints/player.dart:97:5)
<asynchronous suspension>
#4      _SpotifyScreenState._buildSpotifyConnected.<anonymous closure> (package:my_app/screens/spotify.dart:192:23)
<asynchronous suspension>

Is there a way to turn on debug logging so I can see the actual http requests being sent out and see what the issue is with the request?

Additional info:

adamkoch commented 7 months ago

I used Flutter DevTools to inspect the network requests and it appears all fine. It's sending a simple PUT request to: https://api.spotify.com/v1/me/player/play?

Comparing to the sample request in the Spotify docs it looks the same AFAICT. I kept the request body empty for both of them.

hayribakici commented 7 months ago

@adamkoch So far there are no debug tools in this library. However, this is a good idea. I'll create another issue for this.

adamkoch commented 7 months ago

To follow up, I found the issue was that: .player.startOrResume()

Adds an empty request body of "". Which Spotify considers a malformed request which is why it's not working. I looked over the code but couldn't find where to have it return an empty body when there are no parameters supplied. If you have any code pointers please let me know.

adamkoch commented 7 months ago

Perhaps here, default is to set body to empty string vs null: https://github.com/rinukkusu/spotify-dart/blob/v0.11.0/lib/src/spotify_base.dart#L167

rinukkusu commented 3 months ago

Fix is released with v0.13.4!