Copy link to clipboard
Copied
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 2016 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?
Copy link to clipboard
Copied
Two tips:
1) method="POST"
2) Any luck with this?
<cfhttpparam type="header" name="Content-Type" value="application/vnd#chr(46)#api#chr(43)#json">
Or this?
<cfhttpparam type="header" name="Content-Type" value="application/vnd#chr(46)#api#chr(43)#json;charset=UTF-8">
Copy link to clipboard
Copied
appreciate the reply...but neither of those worked.
Copy link to clipboard
Copied
Our posts crossed. I was still editing mine.
What happens when you switch to "POST" method?
Copy link to clipboard
Copied
I will try any and all 😉
attempted as POST also with both headers also...same errors.
Copy link to clipboard
Copied
Sorry to hear that.
Perhaps the content-type application/vnd.api+json is too new for ColdFusion.
You could, as an alternative, install CURL, then do something like:
(The intention 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" />