Error 415- Content-Type header should have application/json

So this error seems like a simple enough fix, however, I already have the Content-Type defined as application/json. I am trying to make a put request to update an asset upon a user clicking a button. I utilized this article to model my put request off of as I could not find documentation in the SDK. Any insight would be greatly appreciated. This error has been driving me nuts. Please see my code snippet below:

                var putHeaders = {'Authorization': "Basic <%= encode(iparam.api_key) %>", 
                                'Content-Type' : 'application/json'};
                var body = {"location_id" : 20000288494}
                var putOptions = { putHeaders: putHeaders, 
                                body: JSON.stringify(body)};
                var baseUrl = `https://${iparam.freshservice_domain}.freshservice.com`;
                var assetURL = `${baseUrl}/api/v2/assets/${asset_id}`;
                console.log(assetURL)
                client.request.put(assetURL, putOptions)

Hi @Kiska_Sanchez,
Good day! Welcome to the community,
There is an issue with your code, Please find the correct snipper below :point_down:

var headers = {'Authorization': "Basic <%= encode(iparam.api_key) %>", 
                                'Content-Type' : 'application/json'};
                var body = {"location_id" : 20000288494}
                var options = { headers, 
                                body: JSON.stringify(body)};
                var baseUrl = `https://${iparam.freshservice_domain}.freshservice.com`;
                var assetURL = `${baseUrl}/api/v2/assets/${asset_id}`;
                console.log(assetURL)
                client.request.put(assetURL, options)

Hope it helps

Thanks

1 Like

That worked! Thank you so much!

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.