0
votes

I am doing a basic PATCH method call to an API using cfhttp and Coldfusion 2021. No matter what I try to do, it changes the content-type on the call to x-www-form-urlencoded when it is set to application/json using cfhttpparam. I tried adding this line from another post, no effect.

<cfhttpparam type="CGI" encoded="false" name="Content_Type" value="application/json; charset=utf-8"<

I tried changing the method to POST and using this line from another post.

<cfhttpparam type="header" name="X-HTTP-Method-Override" value="PATCH">

No matter what it still sends as the wrong content-type and the api disregards it as a result and just sends back a 200 OK that it received a call, but does no update to the data due to the content-type.

I have also tried sending the body as a variable and as a param. Same result.

Does anyone know why it is switching the content-types or how to correct it?

Here is my code for the call to the API.

<cfhttp url="#loc.URLInsertID#"
        method="PATCH"
        timeout="999"
        result="loc.AssetPandaGetObjectDataUpdate">
        <cfhttpparam type="header" name="Accept" value="application/json" />
        <cfhttpparam type="header" name="Content-Type" value="application/json" />
        <cfhttpparam type="header" name="Mimetype" value="application/json" />
        <!--- <cfhttpparam type="CGI" encoded="false" name="Content_Type" value="application/json; charset=utf-8"> --->
        <!--- <cfhttpparam type="header" name="X-HTTP-Method-Override" value="PATCH"> --->
        <cfhttpparam type="header" name="Authorization" value="#Bearer#">
        <!--- <cfhttpparam type="body" name="body" value="#SerializeJSON(loc.bodyElements)#"> --->
        #SerializeJSON(loc.bodyElements)#
</cfhttp>
1

1 Answers

0
votes

This is really a comment, but it is too long.

On this section of code

    <!--- <cfhttpparam type="body" name="body" value="#SerializeJSON(loc.bodyElements)#"> --->
    #SerializeJSON(loc.bodyElements)#

You most likely want to use the body approach. Try to get this to work on Postman first. Usually it is straight forward to replicate the request from there.