/build/static/layout/Breadcrumb_cap_w.png

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.


0 Comments   [ + ] Show comments

Answers (2)

Answer Summary:
Posted by: Hobbsy 2 weeks ago
Red Belt
0

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 weeks ago
Posted by: CoryHatter@BoydCat.com 2 weeks ago
White Belt
0

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.

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ