Sending incorrectly formatted contacts to batch endpoint results in 202

SOLVE
Highlighted
New Contributor

Hi,

 

I'm sending the following json body to the endpoint https://api.hubapi.com/contacts/v1/contact/batch/?hapikey=${apikey}:

[ { "email": "test1@example.com",
    "details": { "firstname": "Test1" } },
  { "email": "test2@example.com",
    "details": { "firstname": "Test2" } } ]

This is wrong, which I figured out quickly, it should be formatted like this:

 

[  { "email": "test1@example.com",
     "properties": [ { "property": "firstname", "value": "Test1" } ] },
   { "email": "test2@example.com",
     "properties": [ { "property": "firstname", "value": "Test2" } ] }
]

 

However, I was very surprised to get a 202 Accepted, instead of a 400 Bad Request.

When I have the proper formatting, but use a non-existing property, I do get the 400.

 

Sending an individual contact with the wrong format to the non-batch endpoint correctly validates the json.

 

It seems like the batch endpoint should do the same structural checking since it's already doing the more expensive checking of the properties.

 

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
HubSpot Moderator

Welcome, @q42jaap.

 

Thanks for bringing this to our attention! I'll have the team take a closer look.

 

I'm curious, though. Why did you attempt with a details object? All of the Contacts API examples I'm familiar with show a properties array. I want to make sure there isn't misleading documentation out there.

Isaac Takushi

HubSpot Developer Support
Reply
0 Upvotes
3 Replies 3
HubSpot Moderator

Welcome, @q42jaap.

 

Thanks for bringing this to our attention! I'll have the team take a closer look.

 

I'm curious, though. Why did you attempt with a details object? All of the Contacts API examples I'm familiar with show a properties array. I want to make sure there isn't misleading documentation out there.

Isaac Takushi

HubSpot Developer Support
Reply
0 Upvotes
New Contributor

Hi Isaac,

 

The details property was an internal representation of the contact object. I forgot to map that representation to the proper format. I was a little bit confused by the 202, but I quickly figured out that I was sending a wrong format.

 

It seems that only the properties are validated and that if there are no properties the validation succeeds. In contrast the non-batch endpoint does verify the complete structure of the json payload. I would expect them to be checked the same way.

 

The logical check of properties in the correct format works the same in both the batch and non-batch endpoints as far as I could see.

 

Jaap

Reply
0 Upvotes
HubSpot Moderator

I appreciate the additional feedback, @q42jaap.

 

I agree that we should also validate the structure of payloads for the batch endpoint to avoid confusing 202 responses. I'll share this with the team and update this thread with relevant details!

 

Isaac Takushi

HubSpot Developer Support
Reply
0 Upvotes