API sample code

LizC655
Participant

API sample code

Below is the sample code and error:

 

curl --location --request POST 'https://api.constantcontact.com/v2/contacts?action_by=ACTION_BY_VISITOR&api_key=ABC' \
--header 'Authorization: Bearer ******-****-****-****-fe6ece0ea069' \
--header 'Content-Type: application/json' \
--data-raw '{
"email_address": {
"address": "test1142021@test.com",
"permission_to_send": "implicit"
},
"first_name": "test",
"last_name": "test"
}'

 

Error:

[
    {
        "error_key""json.field.invalid",
        "error_message""#/email_address: Property was found but is not permitted at this location."
    },
    {
        "error_key""json.field.missing",
        "error_message""#/email_addresses: Property is required but not found."
    }
]
1 REPLY 1
Stephen_T
Moderator

Hello @LizC655,

 

Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.

 

After working on this issue via email, we saw there were a combination of issues between missing elements and an invalid property being used. That invalid property in the code is "permission_to_send". Also the code was missing some brackets, a list to add the contact to, and the opt_in_source for the contact. Just in case, below is an example of the coding with invalid properties removed and missing elements added.

 

POST Address I Used:
https://api.constantcontact.com/v2/contacts?api_key=ABC&action_by=ACTION_BY_VISITOR

 

 

{
"email_addresses":
[
{
"opt_in_source": "ACTION_BY_VISITOR",
"email_address": "test1142021@test.com"
}
],
"first_name": "test",
"last_name": "test",
"lists": [
{
"id": "123456"
}
]
}

 

 

Also, below is a link to documentation which has all a list of all the valid fields when doing a POST for adding a contact.

 

Contacts Collection Endpoint

https://v2.developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST

 

Please feel free to respond to the email if you have any additional questions.

 

Regards,


Stephen T.
API Support Engineer
Did I answer your question? If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.

You're not alone on your email marketing journey. Connect with a Marketing Advisor to see how they can help you develop the right strategy for your business and get the most out of your Constant Contact experience.
Developer Portal

View API documentation, code samples, get your API key.

Visit Page