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.

Adding a Contact through API

SOLVED
Go to solution
Highlighted
Occasional Participant

Adding a Contact through API

Hi, I'm developing a program to add a contact from my system using the API, and when I add the contact the welcome e-mail is sent to the contact I just added.

The thing is I don't want that happen, I have read in the API documentatio and it says that setting up the OptInSource to ActionByCustomer will prevent the system to send the welcome e-mail, but either way this mail is sent.

I'm using C#, the code I'm writing to add the contact looks like this:

 

CC.ConstantContact Contacto = new CC.ConstantContact();

.............

Contacto.OptInSource = CC.ContactOptSource.ActionByCustomer;

CC.ContactOptInList ContactOptInList = new CC.ContactOptInList();   

ContactOptInList.ContactList = new CC.ContactList(LanguageList);                       

string ListID = "4";

ContactOptInList.ContactList = new CC.ContactList(ListID);

ContactOptInList.OptInSource = CC.ContactOptSource.ActionByCustomer;                        Contacto.ContactLists.Add(ContactOptInList);  

 

Do you have any idea about what could be the problem? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Employee

Re: Adding a Contact through API

Hi Marcelo,

 

We are very sorry for any inconvenience this has caused you.  After some testing, we found that ActionByContact was hard coded into the XML string builder for ContactComponent.CS.

 

If you change:

 

data.AppendFormat("<OptInSource>{0}</OptInSource>", optSourceNames[ContactOptSource.ActionByContact]);

to:

 

 

data.AppendFormat("<OptInSource>{0}</OptInSource>", optSourceNames[contact.OptInSource]);

 

Should resolve the issue.

 

We will recompile the code and add the updated code to our repository.  

 

If you have any further questions or issues, please let us know.

 

Thanks,

 

Andrew Weber
Associate Product Manager for EventSpot

View solution in original post

7 REPLIES 7
Highlighted
Moderator

Re: Adding a Contact through API

Problem is your list ID is not valid.  The list ID is a string that is (usually) pulled from a query to the server when pulling lists.  If you want to manually set it, like you're doing, it would need to be in the proper format.  This format is:

 

http://api.constantcontact.com/ws/customers/{username}/lists/{list_id}

 

You would simply have to add the username and the ID number to the format above and that would give you the full ID value for the list in question.  That should solve the probelm you're having (which I believe is a 400 Bad Request with an error message of "Invalid List"). 

 

Also, I'm not sure what the value is for LanguageList, however it appears that that will also give a 400 Bad Request "Invalid List" error as well.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Participant

Re: Adding a Contact through API

There is a mistake in the code I've posted,  the content of ListID is "English" instead of "4",  "English" it's one of the lists that I currently have on the server.

One more thing, I'm using the api method Utility.CreateNewContact(AuthentificationData,Contact) to create the contact.

Highlighted
Occasional Participant

Re: Adding a Contact through API

Hello, I've changed mi code and now I'm using the full ID like you said before, https://api.constantcontact.com/ws/customers/{username}/lists/{list_id}, I'm using https because otherwise I receive an 403 forbidden error.

I'm still having the problem, my contacts receive the welcome e-mail, and I need to solve this in the shortest possible time.

 

Thanks.

Highlighted
Employee

Re: Adding a Contact through API

Hello,

 

Is it possible for you to email us your code?  We can then look at it and get a better understanding as to why this is happening.

 

Regards,

Benjamin Soder
NOC Analyst
Constant Contact
Highlighted
Occasional Participant

Re: Adding a Contact through API

Hello,

I hope the part of the code I sent you yesterday will work for you.

 

Let me know if it works for you

 

Regards

Highlighted
Employee

Re: Adding a Contact through API

Hi Marcelo,

 

We are very sorry for any inconvenience this has caused you.  After some testing, we found that ActionByContact was hard coded into the XML string builder for ContactComponent.CS.

 

If you change:

 

data.AppendFormat("<OptInSource>{0}</OptInSource>", optSourceNames[ContactOptSource.ActionByContact]);

to:

 

 

data.AppendFormat("<OptInSource>{0}</OptInSource>", optSourceNames[contact.OptInSource]);

 

Should resolve the issue.

 

We will recompile the code and add the updated code to our repository.  

 

If you have any further questions or issues, please let us know.

 

Thanks,

 

Andrew Weber
Associate Product Manager for EventSpot

View solution in original post

Highlighted
Occasional Participant

Re: Adding a Contact through API

Hi,

I'm very pleased to tell you that with your help I finally solved this problem. The problem you mentioned was the cause of the unexpected behavior, I changed the code and It worked great. I think this problem is solved.

 

Thank you very much.

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