https json cfhttp post

We received this sample code in php

<?php

$json_request = <<<JSON
{
"api_key": "1231231",
"remote_user_id": "123456",
"firstname": "Teston",
"lastname": "Testor",
"email": "test@example.com",
"remote_product_id": "EXAMPLE_REMOTE_ID",
"amount_paid": "0.00",
"send_email":true
}
JSON;

$eox_api_url = "https://theurl";

$curl_cmd = "/usr/bin/curl -X POST -d '$json_request' $eox_api_url --header \"Content-Type:text/json\"";

$eox_api_response = `$curl_cmd`;

print $eox_api_response

?>

Open in new window


and I am trying to get it to work in coldfusion but getting a I/O Exception: peer not authenticated error message in dump so my guess is I have something wrong in my code

<cfset stFields =
{
"api_key": "123456789012345678901234567890",
"remote_user_id": "1231",
"firstname": "Test",
"lastname": "Test",
"email": "test@test.com",
"remote_product_id": "1231",
"amount_paid": "33",
"send_email":true
}>

<cfhttp url="https://theurl" method="post" result="httpResp" timeout="60">
    <cfhttpparam type="header" name="Content-Type" value="application/json" />
    <cfhttpparam type="body" value="#serializeJSON(stFields)#">
</cfhttp>

Open in new window

digitalwiseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LajuanTaylorCommented:
@digitalwise - I kept getting a CF error when I attempted to use the cfset variable as provided. Therefore, I added a single quote before and after your json data set. In the sample it was not necessary to serialize the json because it's already in a valid name/value pair format. I checked the json as found and using three different output options within my browser.

I used the following online json validator:
http://jsonlint.com/

The CF code I used for testing was basically what you provided:
<cfset stFields ='
{
"api_key": "123456789012345678901234567890",
"remote_user_id": "1231",
"firstname": "Test",
"lastname": "Test",
"email": "test@test.com",
"remote_product_id": "1231",
"amount_paid": "33",
"send_email":true
}'>

<!--- What does the json look like? --->
Test 1 <cfoutput> #serializeJSON(stFields)#</cfoutput><br><br><br>
Test 2 <cfoutput> #stFields#</cfoutput><br><br><br>
Test 3 <br><cfdump var="#stFields#">

Open in new window


As for your authentication error, did you double check the API Key along with the username & password?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.