Reputation: 41
When I was a dev I built a simple .net web application that interacted with my Spotify library through the Spotify APIs. I've recently come back to it to find that my DELETE function, which calls the 'Remove User's Saved Albums' API, no longer works and is getting a 400 server response.
Spotify API - https://developer.spotify.com/documentation/web-api/reference/remove-albums-user
Due to the amount of albums I needed to remove I pass an array of strings in the body of the request, described in the API docs.
I have recently launched the app and taken it for a spin, only to find the delete album functionality no longer works. I'm having difficulty understanding what aspect of the request is incorrect.
This code, which specifies an ID in the URL, receives a 200 success response:
public async Task DeleteAlbumsAsync(string accountToken)
{
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accountToken);
var request = new HttpRequestMessage
{
Method = HttpMethod.Delete,
RequestUri = new Uri("https://api.spotify.com/v1/me/albums?ids=15bBLibQWFnobks4oeRKDB")
};
var response = await _httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
}
This code, which passes the same album ID in the body, receives a 400 error response:
public async Task DeleteAlbumsAsync(string accountToken)
{
var albums = new string[]
{
"15bBLibQWFnobks4oeRKDB"
};
var json = JsonConvert.SerializeObject(albums);
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accountToken);
var request = new HttpRequestMessage
{
Method = HttpMethod.Delete,
RequestUri = new Uri("https://api.spotify.com/v1/me/albums"),
Content = new StringContent(json, Encoding.UTF8, "application/json")
};
var response = await _httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
}
What am I missing and how should the request be properly formed to allow passing the album array in the body? Many thanks
Upvotes: 0
Views: 25