Skip to main content
2Charlie
Inspiring
Mar 21, 2016 1:56 PM UTC
Question

Is this how to send json data?

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 is closed to new replies. Start a new post to keep the conversation going.

    8 replies

    Carl Von Stetten
    Legend
    Mar 21, 2016 3:28 PM UTC

    Does it work?

    Translate
    2Charlie
    2CharlieAuthor
    Inspiring
    Mar 21, 2016 3:37 PM UTC

    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.

    Translate
    Carl Von Stetten
    Legend
    Mar 21, 2016 3:41 PM UTC

    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

    Translate