We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

json array issue when posting an individual contact

SOLVED
Go to solution
ourtime
Frequent Participant

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
Elijah_G
Member

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
Elijah_G
Member

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