APIs & Integrations

boopathi_s
Member

How to create a new contact in hubspot via RESTAPI

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

0 Upvotes
9 Replies 9
3PETE
HubSpot Employee
HubSpot Employee

How to create a new contact in hubspot via RESTAPI

@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.

0 Upvotes
boopathi_s
Member

How to create a new contact in hubspot via RESTAPI

@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.

0 Upvotes
boopathi_s
Member

How to create a new contact in hubspot via RESTAPI

how to rectify this.Any suggestion would help me.

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

How to create a new contact in hubspot via RESTAPI

@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.

0 Upvotes
boopathi_s
Member

How to create a new contact in hubspot via RESTAPI

@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

0 Upvotes
boopathi_s
Member

How to create a new contact in hubspot via RESTAPI

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

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

How to create a new contact in hubspot via RESTAPI

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

0 Upvotes
boopathi_s
Member

How to create a new contact in hubspot via RESTAPI

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#">
0 Upvotes
boopathi_s
Member

How to create a new contact in hubspot via RESTAPI

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

0 Upvotes