Create Constituent endpoint and multiple email addresses

Hello everyone

I am using the POST Constituent API call in order to create a new constituent record. In my POST request, I want to create the constituent with 2 email address records (a business type and a personal type). The guidance has an example of a single email but I want an email array to create the constituent with the 2 email addresses in the one call. Is this possible? Im getting error messages when attempting:

Thank you

Damon

[{"message":"Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ConstituentEmailAddressAdd' because the type requires a JSON object (e.g. {\\"name\\":\\"value\\"}) to deserialize correctly.\\r\\nTo fix this error either change the JSON to a JSON object (e.g. {\\"name\\":\\"value\\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\\r\\nPath 'email', line 1, position 420.","error_code":400,"raw_message":"Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ConstituentEmailAddressAdd' because the type requires a JSON object (e.g. {\\"name\\":\\"value\\"}) to deserialize correctly.\\r\\nTo fix this error either change the JSON to a JSON object (e.g. {\\"name\\":\\"value\\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\\r\\nPath 'email', line 1, position 420."}]

Comments

  • Hi Damon,

    At this time, the endpoint that you're calling doesn't allow providing multiple emails for the constituent - just a single value is supported (you can see this in the docs on the endpoint reference page). So to accomplish this, you'll need to make two API calls:

    1. First call CreateConstituent to create the constituent with one email address (and to get the ID of the newly created constituent)
    2. Then call CreateConstituentEmailAddress to create the second email address, providing the ID of the newly created constituent in the request.

    I hope this helps - if you'd like, feel free to file a suggestion for this functionality on the idea bank here:

  • Thank you for the reply Ben, its much appreciated. Im quite happy to make the two API calls, I just wanted to be sure.

    Kind Regards

    Damon