How to create a new contact in hubspot via RESTAPI

contacts

#1

Hi I am new to hub spot, I wish to create a new contact through rest api.
My piece of code is:

<cfhttp url="https://api.hubapi.com/contacts/v1/contact/?hapikey=demo" method="post" result="httpResp" timeout="60">
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="body" value="#serializeJSON(stFields)#">
<cfdump var="#httpResp#" label="HTTP response">

If I dump the value it shows “Json node is missing child properties” what might be the error.How to fix it.
Thanks in advance.
see this link for cfdump output:
http://imgur.com/a/DoQII


#2

I received this error.400 Bad Request how to rectify this.


#3

@boopathi_s I would try removing the outside {} it looks like you almost have duplicate open braces and closing braces. try to follow this from the dev documentation. (http://developers.hubspot.com/docs/methods/contacts/create_contact)

{
        "properties": [
            {
                "property": "email",
                "value": "testingapis@hubspot.com"
            },
            {
                "property": "firstname",
                "value": "Adrian"
            },
    ]
}

Let me know if that helps at all.


#4

@pmanca If i removed the open and closed braces in cfset and commented serialise json .then It shows the invalid json input error below screen shot.


#5

how to rectify this.Any suggestion would help me.


#6

@boopathi_s I am unfamiliar with CFML but I found some documentation here.

http://www.learncfinaweek.com/week1/JSON/

Do you need to wrap the JSON in ‘’ before you serialize it?
Hopefully you can follow the documentation above for creating a CFML struct and then serializing it to JSON. If this doesn’t help please let me know so I can continue to look into it.


#7

@pmanca Your data is already serialized. so don’t need to serialize it.that’s why i remove the line.Give some alternative approach if you have any.thanks for reply bro


#8

@pmanca I fixed the issue bro…thanks for reply bro…


#9

@boopathi_s That’s Great! Do you mind letting me know what it was? My own curiosity is killing me now.


#10

remove the serializejson and put stfields only in cfhttpparam.Keep help me bro…i have lot of tasks to do from now onwards.:smirk:

<cfhttpparam type="body" value="#stFields#">