adamint / spotify-web-api-kotlin

Spotify Web API wrapper for Kotlin, Java, JS, and Native - Targets JVM, Android, JS (browser), Native (Desktop), and Apple tvOS/iOS. Includes a Spotify Web Playback SDK wrapper for Kotlin/JS, and a spotify-auth wrapper for Kotlin/Android.
https://adamint.github.io/spotify-web-api-kotlin-docs/
MIT License
194 stars 21 forks source link

Market.FROM_TOKEN causes HTTP 400 #324

Closed chuck-stein closed 1 year ago

chuck-stein commented 1 year ago

Describe the bug When making a request with Market.FROM_TOKEN, the request will fail with SpotifyException.BadRequestException due to an HTTP 400 error.

To Reproduce Steps to reproduce the behavior:

  1. Call an endpoint that takes in a market parameter, specifying Market.FROM_TOKEN. For example:
spotifyClientApi.browse.getRecommendations(market = Market.FROM_TOKEN, seedTracks = listOf(/* any track IDs */))
  1. SpotifyException.BadRequestException is thrown, with error code 400.

Expected behavior A successful response from the endpoint, providing content (such as recommended tracks) relevant to the user's current market/country (pulled from their auth token).

Smartphone (please complete the following information):

Additional context The 400 error is happening because the market parameter is resolved by getting the enum name, which is FROM_TOKEN. However, this is not a valid Spotify market -- it should be from_token in all lowercase instead.

adamint commented 1 year ago

Yep, this is correct. Enum name shouldn't be used for this special case. I'll fix this and make sure a test references this token value.

adamint commented 1 year ago

Closing with release 4.0.1. Please download and try!

chuck-stein commented 1 year ago

Thanks for looking into this. Unfortunately it looks like the fix only affected certain endpoints. After updating to the latest version, I am still getting 400s for the endpoints I was hitting, namely:

I do know that I updated correctly, because if I click into the artists.getArtistTopTracks endpoint, for example, I do see it using the new market.getSpotifyId() extension. However, if I click into the endpoints I listed above, I still see them using market?.name.

I'm also guessing that isn't an exhaustive list, so it's probably worth just searching for and replacing all usages of market.name. Thanks again for the help!