Converting cURL request to cfhttp

I am successfully able to execute the following curl request using Git Bash.

curl -X PUT \
  https://www.cospheric.com/api/v1/products/356 \
 -H 'Content-Type: application/json' \
  -H 'X-AC-Auth-Token: {mytoken}' \
  -d '{"quantity_on_order": 40}' 

I am using the following code so that it can run in CF.

<cfhttp  method="PUT"  url="https://www.cospheric.com/api/v1/products/356">
	<cfhttpparam type="header" name="X-AC-Auth-Token" value="{my token}" />
	<cfhttpparam type="header" name="Content-Type" value="application/json"> 
	<cfhttpparam type="header" name="Accept" value="*/*"> 
	<cfhttpparam name="quantity_on_order" encoded="no" type="FORMFIELD" value="40" />
</cfhttp>

However, when I run this code, I get he following error:

{"status_code":500,"message":"Internal Server Error","details":"Object reference not set to an instance of an object."}

Can anyone please help me understand why it works fine when I run the curl statement, but failing in CF? Any help would be much appreciated.

I think curl -d is data sent in body

Try changing type=“FORMFIELD”

To type=“BODY”

And value would be

{“quantity_on_order”: 40}
3 Likes

Thank you webonix!!!

This resolved my issue. Here is the code I used…

 <cfset body_content = "{""quantity_on_order"": 44}">

<cfhttp  method="PUT"  url="https://www.cospheric.com/api/v1/products/356">
	<cfhttpparam type="header" name="X-AC-Auth-Token" value="{my Token}" />
	<cfhttpparam type="header" name="Content-Type" value="application/json"> 
	<cfhttpparam type="header" name="Accept" value="*/*"> 
	<cfhttpparam name="on_order" encoded="no" type="BODY" value="#body_content#" />
</cfhttp>
1 Like