0

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?

rrk
  • 15,677
  • 4
  • 29
  • 45
Torsten
  • 29
  • 3

2 Answers2

0

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" />
BKBK
  • 484
  • 2
  • 9
  • My thoughts also are ColdFusion 2016 at very least does not support content-type application/vnd.api+json. I have been able to get the cfexecute to work in saving to a file. It will not save the result to a variable though. And atttempting to read the html page (or txt or .json) will not load into a usable to json. How would the api result be incorporated back into a usable JSON variable as if it came from CFHTTP. – Torsten Jan 29 '20 at 15:38
  • The issue seems to be writing the html file and attempting to read within the same code. The file is not yet recognized looks like. If I run code against the file created previously (without actually running the api again via curl) it will load. Still creates the issue of needed to use the json as it comes in - cfexecute has a variable param - why does it not hold the json the same as the cfhttp would? – Torsten Jan 29 '20 at 15:58
0

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>
Torsten
  • 29
  • 3