API - upload multiple contacts - failing with error


#1

Hello,
I am trying to post multiple contacts to my hubspot account.

URL:

https://api.hubapi.com/contacts/v1/contact/batch/?hapikey=XXpinkSocksXXX

body (depersonalised):

[
{
"email": "bbbb@gmail.com",
"properties": [
{
"property": "firstname",
"value": "billy"
},
{
"property": "lastname",
"value": "bloggs"
},
{
"property": "producttype",
"value": "Life"
},
{
"property": "phone",
"value": "0444444444"
},
{
"property": "state",
"value": "WA"
},
{
"property": "utm_campaign",
"value": "G3_Life"
}
]
},
{
"email": "aaaa@gmail.com",
"properties": [
{
"property": "firstname",
"value": "billy"
},
{
"property": "lastname",
"value": "bloggs"
},
{
"property": "producttype",
"value": "Life"
},
{
"property": "phone",
"value": "0444444444"
},
{
"property": "state",
"value": "QLD"
},
{
"property": "utm_campaign",
"value": "G3_Life"
}
]
}
]

I get the following error response:

<Response [400]> {"status":"error","message":"Json node is missing child properties","correlationId":"XXXXX","requestId":"XXXXX"}

To me, this looks like the correct format according to the API docs (at this location):


I can confirm that the properties "utm_campaign" and "producttype" exists in our hubspot account.

I have no problems uploading single contacts to Hubspot through the API, using the different url.

Can anyone tell me what is wrong with my request?

Regards,
Peter


#2

Hi @Peterware,

That error generally means that HubSpot isn't able to find the properties field in your request body. This is most often due to invalid JSON, but yours appears to be correct. Is the JSON you included here the raw body that's sent to HubSpot? Is it possible that it's being malformed somehow before being included in the request body?

Also, are you sure you're including the correct Content-type: application/json header?


#3

I haven't specified Content-type anywhere, but my API call to upload a single contact works perfectly, and it is almost identical - different URL, 'https://api.hubapi.com/contacts/v1/contact/?hapikey=XXXX', and json content contains only one contact, but otherwise quite similar.
Has anyone else had issues bulk uploading contacts?


#4

Just to add more detail, below is the python command I am using:

response=requests.post(headerUrl,data=jsonString)
Where headerURL (URL) and jsonString (body) are exactly as per documented in this thread, except obviously the below text

XXpinkSocksXXX

is replace in my python code with the correct twenty-something digit hapikey.

Regards,
Peter


#5

Hi @Peterware,

Can you try explicitly setting the content type? While it sounds like it works without it when making requests to create a single contact, it's technically required and might be the root of the issue. The command should look something like this:

headers = {"Content-Type": "application/json"}
response=requests.post(headerUrl,data=jsonString, headers=headers)


#6

Thanks Derek.
I ran
headers = {"Content-Type": "application/json"}
response=requests.post(headerUrl,data=jsonString,headers=headers)
This also returned the error
<Response [400]> {"status":"error","message":"Json node is missing child properties","correlationId":"b0...","requestID":"c9..."}


#7

Do you have a sample upload json file, url and header that you could send me (obviously remove hapikey and depersonalize first if required) that I can modify and try in our account?


#8

Hi @Peterware,

That's very strange. Here's an example that I was able to get working:

requestUrl='https://api.hubapi.com/contacts/v1/contact/batch/?hapikey=XXXXX'
requestBody='[{"email":"pythontest@gmail.com","properties":[{"property":"firstname","value":"Python"},{"property":"lastname","value":"Test"}]}]'
requestHeaders={"Content-type":"application/json"}
response=requests.post(requestUrl, data=requestBody, headers=requestHeaders)

That gave me:

<Response [202]>

And created the contact in my portal. Can you try that code, just so we can establish a working example?


#9

Thanks Derek.
I have it working now. Seems I may have messed up the URL at some stage.
Regards,
Peter