Cannot deserialize value of type java.util.ArrayList<com.infusionsoft.api.rest.v2.common.dto.EmailAddressRequest>

Hi Guys,

I am POSTing to https://api.infusionsoft.com/crm/rest/v2/contacts

Example:

{
    "email_addresses": {
        "0": {
            "email": "email@gmail.com",
            "field": "EMAIL1",
            "opt_in_reason": "Purchased Product"
        }
    }
}

I am getting the following error:

{
        "code": 400,
        "message": "JSON parse error: Cannot deserialize value of type `java.util.ArrayList<com.infusionsoft.api.rest.v2.common.dto.EmailAddressRequest>` from Object value (token `JsonToken.START_OBJECT`); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.util.ArrayList<com.infusionsoft.api.rest.v2.common.dto.EmailAddressRequest>` from Object value (token `JsonToken.START_OBJECT`)\n at [Source: (PushbackInputStream); line: 1, column: 20] (through reference chain: com.infusionsoft.api.rest.v2.contact.dto.CreatePatchContactRequest[\"email_addresses\"])",
        "status": "Bad Request",
        "details": [
            {
                "domain": "General",
                "resource": ""
            }
        ]
    }

Can anybody spot what is wrong here?

It looks like you are passing “email_addresses” as a JSON object; it should be an array.

"email_addresses": [
    {
      "email": "string",
      "field": "EMAIL_FIELD_UNSPECIFIED",
      "opt_in_reason": "string"
    }
  ],

https://developer.infusionsoft.com/docs/restv2/#!/Contact/createContactUsingPOST_3

1 Like

Thanks Tom, looks like some middlewear was converting my array into an object. Sorted now.

1 Like