Generic Bad Request error from Contacts API


#1

Dadams, when we get back an error from HubSpot when we are passing over invalid field values, we typically get a response back that includes the field in question and the value that was bad. However, recently I’ve noticed we have gotten a few errors where the error, while looks similar to these standard invalid field value errors, is not showing any real details. Here’s an example of what it’s looking like:

HTTPError: PUT http://localhost:8801/agents/hubspot0/records/contact/40103 => 422 Unprocessable Entity / upstream error / {‘upstreamError’: ‘Bad Request’, ‘upstreamCode’: 400}

So it’s just saying Bad Request. My one suspicion was perhaps when there is more then one field causing a problem, we are not properly recognizing the response you are sending and therefore are not including the details. Any chance you can send what an example response might look like from the contacts API when more then 1 field has invalid fields and therefore we can’t write the changes?


#2

Hey Luke,

Can you please attach an example request body and the endpoint you’re using.

Sebastian


#3

Sebastian,

Sorry for the delay on your question. Here’s an example request that triggered this type of response:

POST /contacts/v1/contact
{‘properties’: {‘monthly_credit_card_processing_volume_estimate_’: ‘20k’, ‘numemployees’: ‘1’, ‘your_emv_stage’: ‘have_not_done_anything’, ‘how_can_we_help_you_’: ‘general’, ‘business_industry’: ‘Utility’, ‘zip’: ‘1748’, ‘lastname’: ‘Jill A. Tanzi’, ‘firstname’: ‘Dr.’}}

In this request, I know that the monthly_credit_card_processing_voluem_estimate value is invalid as well as your_emv_stage as both of these are drop down selects in this customer’s portal and these options do not exist.

Usually when invalid field options are present, the error shows the full details of what field is in question. But as there is more then one, our suspicion is that this shows up differently and we may then need to treat it differently in order to display properly in our logs.


#4

Hey Luke,

it looks like your provided JSON doesn’t match the format we expect. Our Contacts API takes in an array of property-value objects, so your body should look more like this:

{
  "properties": [
    {
      "property": "monthly_credit_card_processing_volume_estimate_",
      "value": "20k"
    },
    {
      "property": "numemployees",
      "value": "1"
    },
    {
      "property": "your_emv_stage",
      "value": "have_not_done_anything"
    },
    {
      "property": "how_can_we_help_you_",
      "value": "general"
    },
    {
      "property": "business_industry",
      "value": "Utility"
    },
    {
      "property": "zip",
      "value": "1748"
    },
    {
      "property": "lastname",
      "value": "Jill A. Tanzi"
    },
    {
      "property": "firstname",
      "value": "Dr."
    }
  ]
}

I’m not sure why you got a 402, though. A body like that should’ve should have returned a 400 complaining about the json.