0
votes

I am attempting to run a simple REST api with ColdFusion and receiving same error regardless of attempt. The call works fine in Postman with the 4 params. But cant recreate in ColdFusion CFHTTP.

<cfhttp url="https://api.sandbox.scoutrfp.com/v3/contracts" method="GET" result="ITEM_INFO">
    <cfhttpparam type="header" name="X-Api-Key" value="#variables.API_KEY#">
    <cfhttpparam type="header" name="X-User-Token" value="#variables.USER_TOKEN#">
    <cfhttpparam type="header" name="Content-Type" value="application/vnd.api+json">
    <cfhttpparam type="header" name="X-User-Email" value="#variables.USER_EMAIL#"> 
</cfhttp>

I have replaced the header with type cgi as

<cfhttpparam type="CGI" encoded="false" name="Content_Type" value="application/vnd.api+json">

I have added all temp headers that postman sends.

Always same error: Missing or incorrect Content-Type header for JSON:API: Expected request to include 'Content-Type: application/vnd.api+json

Seems CFHTTP tag not properly sending value "application/vnd.api+json" - perhaps encoding it incorrectly in some fashion? Is there another means to send this Content-Type via CFHTTP to get a response?

2
Did you tried with content-type as application/json ?Kannan.P
I did - but the vendor is wanting to actually see the application/vnd.api+json as content-type...Torsten
What happens when you switch to "POST" method?BKBK

2 Answers

0
votes

The content-type application/vnd.api+json might be too new for ColdFusion.

Another way to send the content-type header via HTTP is to use Curl

(The intention in the code is to save the result in the current directory. That is, the directory containing this CFM file)

<!--- Use your own path to the Curl executable --->

<cfexecute name = "C:\bin\curl-7.35.0-win64\bin\curl.exe" 
     arguments = ' -H "X-Api-Key:#variables.API_KEY#" -H "X-User-Token:#variables.USER_TOKEN#" -H "Content-Type:application/vnd.api+json" -H  "X-User-Email:#variables.USER_EMAIL#" https://api.sandbox.scoutrfp.com/v3/contracts ' 
outputfile="#expandPath('.')#\ITEM_INFO.html" />
0
votes

using an extra header for X-HTTP-Method-Override = GET after changing method to POST worked. The Curl solution also worked with an inserted after the cfexecute and before attempting to read the newly created file written with the returned api content.

 <cfhttp url="https://#variables.ENVIRONMENT#/v3/contracts" method="POST" result="ITEM_INFO">

            <cfhttpparam type="header" name="X-Api-Key" value="#variables.API_KEY#">
            <cfhttpparam type="header" name="X-User-Token" value="#variables.USER_TOKEN#">
            <cfhttpparam type="header" name="Content-Type" value="application/vnd.api+json">
            <cfhttpparam type="header" name="X-User-Email" value="#variables.USER_EMAIL#">
            <cfhttpparam type="header" name="X-HTTP-Method-Override" value="GET">
    </cfhttp>