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.

Issues with API v2

Highlighted
Visitor

Issues with API v2

hello,

 

I am new to ConstantContact, and was playing around with the API to understand how things work. I was trying to do an upload of some 18k contacts through the API to my constant contact account. Before I did that, there were about 18k contacts already in my account which I deleted entirely.

 

When I tried to run the code that uploads contacts using AddContact() method, I was getting an exception that said "contact with email ID already exists". I do not have any contacts in my account so the exception error did not make sense to me. When I debugged the application, I observed that the contact with the same emailID was being found and that the existing contact status is "REMOVED".

 

I am confused as to whether this is some kind of a bug in the API. Can someone help me with this.

 

 

Here is my relavant C# code:

 

foreach (DataRow row in dtUsers.Rows)
            {
                bool contactExists = false;

                if (contactService.GetContacts(Convert.ToString(row["sEmailID"]), null, null, null).Results.Count > 0)
                {
                    contactExists = true;
                }

                if (!contactExists)
                {
                    Contact ct = new Contact();
                    ct.FirstName = Convert.ToString(row["sFirstName"]);
                    ct.LastName = Convert.ToString(row["sLastName"]);
                    ct.Id = Convert.ToString(row["sID"]);
                    ct.CompanyName = Convert.ToString(row["sOrganizationName"]);
                    ct.Status = "ACTIVE";

                    EmailAddress em = new EmailAddress(Convert.ToString(row["sEmailID"]));
                    ct.EmailAddresses.Add(em);

                    ct.Lists.Add(listToUse);

                    contactService.AddContact(ct, false);
                    contactsCreated++;
                }

 

For each row of the 18k rows in dtUsers, I get ContactExists=true, but the fact is I do not have any contacts in my account at all.

 

 

Thanks,

 

Phani.

 

 

1 REPLY 1
Highlighted
Honored Contributor

Re: Issues with API v2

Hello,

 

In this case what you are seeing is actually the expected behavior for our APIs when a contact is deleted. This is because our system soft-deletes contacts so that they can be later restored with their previous details intact. As a result of this, your code is detecting these deleted contacts with the expected status of REMOVED.

 

For an integration that will be modifying contacts individually, the correct approach is to search for an existing contact, and then either update the existing contact or create a new contact accordingly. You can read more about the suggested approach for managing contacts here: http://developer.constantcontact.com/docs/developer-guides/working-with-contacts.html#create_contact

 

In a case such as yours where you will be updating a large number of contacts, I would advocate the use of our asynchronous bulk import API, as it will automatically add/update contacts as appropriate and avoids the difficulty of manually detecting and handling that situation for each individual contact. You can find the API documentation for bull import here:

http://developer.constantcontact.com/docs/bulk_activities_api/bulk-activities-import-contacts.html

 

And in order to implement this with the .NET SDK, you will need to use the following:

  • ActivityService
  • AddContacts
  • AddContactsImportData

 

The basic process is to assemble a list of AddContactsImportData objects (with each instance representing one contact), and use them along with a set of lists and columns to populate the AddContacts object. You then use the ActivityService.CreateAddContactsActivity method to initiate the import.

 

If you have any questions for me, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer
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