APIs & Integrations

q42jaap
Member

Sending incorrectly formatted contacts to batch endpoint results in 202

SOLVE

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.

 

0 Upvotes
1 Accepted solution
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Sending incorrectly formatted contacts to batch endpoint results in 202

SOLVE

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

Associate Certification Manager

View solution in original post

0 Upvotes
4 Replies 4
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Sending incorrectly formatted contacts to batch endpoint results in 202

SOLVE

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

Associate Certification Manager
0 Upvotes
q42jaap
Member

Sending incorrectly formatted contacts to batch endpoint results in 202

SOLVE

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

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Sending incorrectly formatted contacts to batch endpoint results in 202

SOLVE

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

Associate Certification Manager
0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Sending incorrectly formatted contacts to batch endpoint results in 202

SOLVE

I should have updated this thread earlier, but the batch contacts endpoint should no longer respond with a 202 if the payload is improperly formatted.

 

When POSTing the following:

[ 
   { 
      "email":"batch_test_1@example.com",
      "details":{ 
         "firstname":"Batch Test1"
      }
   },
   { 
      "email":"batch_test2@example.com",
      "details":{ 
         "firstname":"Test2"
      }
   }
]

A 400 error is returned with the following message:

{
  "status": "error",
  "message": "Errors found processing batch update",
  "correlationId": "de730f87-cc0d-46ab-b82b-f05c60e90188",
  "failureMessages": [
    {
      "index": 0,
      "error": {
        "status": "error",
        "message": "You need to supply properties to change for the contact."
      }
    },
    {
      "index": 1,
      "error": {
        "status": "error",
        "message": "You need to supply properties to change for the contact."
      }
    }
  ],
  "requestId": "ca3cd4e5adc15b48adf9e5416d1547d2"
}

Isaac Takushi

Associate Certification Manager
0 Upvotes