The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

json array issue when posting an individual contact

SOLVED
Go to solution
Highlighted
Occasional Contributor

json array issue when posting an individual contact

I'm getting this message when trying to post an individual contact through https://api.constantcontact.com/v2/contacts

 

json.payload.type.unexpected:We expected a json array but we received an a json object for one of the fields in the payload.

 

I'm using the .NET wrapper and it is building the json like this:

 

{"addresses":[],"custom_fields":[],"email_addresses":[{"email_address":"supercamilo@gmail.com","opt_out_date":"2014-07-25T00:00:00-04:00","status":"OPTOUT"}],"lists":[{"created_date":"2014-07-28T19:14:34.000Z","id":"2047522211","modified_date":"2014-07-28T19:14:34.000Z","name":"CMS Email Synced","status":"HIDDEN"}],"notes":[],"status":"UNCONFIRMED"}

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Honored Contributor

Re: json array issue when posting an individual contact

Hello,

 

After looking into this, the error is actually being thrown because you're including an opt-out date on the contact when you create it. This is significant because that field is read-only and not valid when creating a new contact. If your goal is to import a contact directly to the unsubscribed category, that is unfortunately not possible through the API at this time. You can however immediately unsubscribe a contact after adding them by using the DeleteContact method. Here's an example:

 

ConstantContact ctct = new ConstantContact(API_KEY);
Contact unsubscribed = new Contact(), newContact;
// Set Contact Data Here

// Add the contact to CTCT and collect the API response with ID.
newContact = ctct.AddContact(unsubscribed);

// Delete(unsubscribe) the new contact immediately
ctct.DeleteContact(newContact);

 

If you are still having any trouble after this, please let us know!

 

Best Regards,

Elijah G.
API Support Engineer

View solution in original post

1 REPLY 1
Highlighted
Honored Contributor

Re: json array issue when posting an individual contact

Hello,

 

After looking into this, the error is actually being thrown because you're including an opt-out date on the contact when you create it. This is significant because that field is read-only and not valid when creating a new contact. If your goal is to import a contact directly to the unsubscribed category, that is unfortunately not possible through the API at this time. You can however immediately unsubscribe a contact after adding them by using the DeleteContact method. Here's an example:

 

ConstantContact ctct = new ConstantContact(API_KEY);
Contact unsubscribed = new Contact(), newContact;
// Set Contact Data Here

// Add the contact to CTCT and collect the API response with ID.
newContact = ctct.AddContact(unsubscribed);

// Delete(unsubscribe) the new contact immediately
ctct.DeleteContact(newContact);

 

If you are still having any trouble after this, please let us know!

 

Best Regards,

Elijah G.
API Support Engineer

View solution in original post

Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured