Skip to main content
2Charlie
Inspiring
March 21, 2016
Question

Is this how to send json data?

  • March 21, 2016
  • 1 reply
  • 4985 views

I'm trying to send JSON data via CFHTTP. Is this all I need or do I need to do anything else? I want make sure I'm not missing anything.

<cfhttp url="https://app.kb.com/api/head/comment.json" method="post" timeout="15" throwonerror="true" >

  <cfhttpparam type="url" name="_authbykey" value="56ec1f0123131c78636142d6">

   <cfhttpparam type="url" name="project_id" value="55c4ffd123131c527e294fe6">

   <cfhttpparam type="url" name="article_id" value="#artID#">

  <cfhttpparam type="url" name="content" value="#form.message#" />

   <cfhttpparam type="url" name="public_name" value="#form.name#" />

   <cfhttpparam type="url" name="public_email" value="#form.mailfrom#" />         

</cfhttp>

Thank you!

    This topic has been closed for replies.

    1 reply

    Carl Von Stetten
    Legend
    March 21, 2016

    Does it work?

    2Charlie
    2CharlieAuthor
    Inspiring
    March 21, 2016

    I got no errors but I am unable to retrieve the data after I've sent it.

    <cfhttp url="https://app.kb.com/api/head/comment.json" method="post" timeout="15" throwonerror="true" >

      <cfhttpparam type="url" name="_authbykey" value="56ec1f1232131c78636142d6">

         <cfhttpparam type="url" name="project_id" value="55c4ffd123131c527e294fe6">

         <cfhttpparam type="url" name="article_id" value="#artID#">

         <cfhttpparam type="url" name="content" value="#serializeJSON(form.message)#" />

         <cfhttpparam type="url" name="public_name" value="#serializeJSON(form.name)#" />

         <cfhttpparam type="url" name="public_email" value="#serializeJSON(form.mailfrom)#" />

    </cfhttp>

    I've tried the serializeJSON() but I'm not sure if that's all I need. I've read this thread at StackOverFlow and it seemed that I've to build the string myself. However, that thread was about two years ago. I wonder if there is any changes in ColdFusion that does not require me to build the string myself.

    Carl Von Stetten
    Legend
    March 21, 2016

    You need to send everything as a JSON string inside of an <cfhttpparam type="body">.  This StackOverflow post may help: http://stackoverflow.com/questions/8932973/how-to-post-json-data-to-remote-api-using-coldfusion-cfhttp