KACE SMA API - "Unsupported Media Type" error when trying to delete an asset
Currently, I am able to get, create, and update assets using the Kace SMA API, but I get the following response when I try to delete an asset:
{"errorCode":-1,"errorDescription":"Unsupported Media Type"}I'm sending a delete request as /api/asset/assets/{id}:
public class KaceClient{
public HttpClient Client { get; }
public KaceClient(HttpClient client)
{
Client = client; Client.BaseAddress = new Uri("https://kacesma/");
Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Client.DefaultRequestHeaders.Add("x-kace-api-version", "5");
}
}public async Task<AssetPostResponse?> DeleteAssetInKace(int id)
{
Uri = string.Format($"https://kacesma/api/asset/assets/{id}");
await Login();
using HttpRequestMessage request = new(HttpMethod.Delete, Uri);
using HttpResponseMessage response = await _client.Client.SendAsync(request);
// The response I get back is the error I mentioned above
var responseString = await response.Content.ReadAsStringAsync();
var kaceApiResponse = JsonConvert.DeserializeObject<AssetPostResponse>(responseString);
...
return kaceApiResponse;
}
As I mentioned, I have no issues sending GET, POST, and PUT requests, such as:
- GET /api/asset/assets
- GET /api/asset/assets/{id}
- PUT /api/asset/assets/{id}
- POST /api/asset/assets
Do I need to specify a different media type somewhere for deletes? Removing the line...
Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));...does not resolve the issue.
Answers (2)
I would log a KACE support ticket if I was you.....
Comments:
-
Thanks for the suggestion! I did find a resolution / work-around, which I'll post in the answer section. - CoryHatter@BoydCat.com 2 years ago
Top Answer
Strangely, adding a blank body to the request allows it to complete:
request.Content = new StringContent("", Encoding.UTF8, "application/json");request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
Considering this is a DELETE request, I wouldn't expect a body to be required.