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.

add contacts in bulk

SOLVED
Go to solution
Highlighted
Solution Provider

add contacts in bulk

How do i add contacts in bulk with single request.

Any sample code????

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Honored Contributor

Re: add contacts in bulk

Hello,

 

In the Constant Contact API, we provide a bulk import API that allows you to send large batches of contacts to be processed asynchronously. You can read more about this endpoint here: http://developer.constantcontact.com/docs/bulk_activities_api/bulk-activities-import-contacts.html

 

Is there a specific language or framework that you are working on/prefer to work on? There are some code samples that can be found in other posts on the forums. Here are a couple of those posts: 

 

 

If you can provide a bit of context, I'm happy to provide some additional resources to get you up and running!

 

Sincerely,

 

Elijah G.
API Support Engineer

View solution in original post

10 REPLIES 10
Highlighted
Honored Contributor

Re: add contacts in bulk

Hello,

 

In the Constant Contact API, we provide a bulk import API that allows you to send large batches of contacts to be processed asynchronously. You can read more about this endpoint here: http://developer.constantcontact.com/docs/bulk_activities_api/bulk-activities-import-contacts.html

 

Is there a specific language or framework that you are working on/prefer to work on? There are some code samples that can be found in other posts on the forums. Here are a couple of those posts: 

 

 

If you can provide a bit of context, I'm happy to provide some additional resources to get you up and running!

 

Sincerely,

 

Elijah G.
API Support Engineer

View solution in original post

Highlighted
Solution Provider

Re: add contacts in bulk

Hello,

 

I'm Using  .NET SDK: https://community.constantcontact.com/t5/Getting-Started-with-API-s/uploading-importing-new-contact....

 

I have downloaded CTCT library, but it doesn't contain ConstantContact class.

 

May be it would be an old version.

Please help me to get latest version of CTCT library. 

 

Using bulk activity for uploading contacts, it requires API key and Access token, Can you please tell me from where these can be obtained??

 

Thank you.

Highlighted
Honored Contributor

Re: add contacts in bulk

Hello,

 

The issue that you're running into is that the current version of the .NET SDK has been updated to use a slightly different class structure. Thus that code is no longer correct. However, I was able to take the code and update it to work with the current version of the SDK.

 

In regards to API key and Access token, you can get both by following the first three steps here: 

https://constantcontact.mashery.com/

 

New Code for bulk import contacts with .NET SDK:

// In order to bulk import contacts, we will need a List of AddContactsImportData objects, a single AddContact object, and a Constant Contact object.
// We also need two List<String> instances for our contact lists and import columns.
IList<AddContactsImportData> contactsToAdd = new List<AddContactsImportData>();
IList<String> lists = new List<String>(), columns = new List<String>();
AddContacts importActvity;

// To create an instance of the ConstantContactFactory class, you will need an API key and Access Token. 
// You can find information about how to obtain these in our Get Started guide here:
// http://developer.constantcontact.com/get-started.html

IUserServiceContext userServiceContext = new UserServiceContext("ACCESS_TOKEN", "API_KEY");
_cc = new ConstantContactFactory(userServiceContext);

IActivityService activityService;
activityService = _cc.CreateActivityService();

// This is a very simple loop that demonstrates how to add 100 identical contacts through a bulk activity
// By using a loop to iterate through your own data, this could easily be used to create a list of unique contacts.
for (var i = 1; i < 100; i++)
{
    
    // First we create an instance of the AddContactsImportData class
    var currentContact = new AddContactsImportData();
    var currentAddress = new Address();
    // Then we add and Email address, First Name, and Last Name
    currentContact.EmailAddresses.Add("exampleemail@nullmailer.com");
    currentContact.FirstName = "Example";
    currentContact.LastName = "Contact";
    currentAddress.AddressType = AddressType.Business;
    currentAddress.Line1 = "Address Line 1";
    currentAddress.StateCode = "OR";
    currentAddress.City = "Portland";
    currentAddress.PostalCode = "12345";
    currentContact.Addresses.Add(currentAddress);
    
    // Then we add it to the List we created and continue the loop.
    contactsToAdd.Add(currentContact);
}

// Once the list of contacts is created, we can then create the activity.
// We will start by assigning the contact list. If you do not know your List ID, it can be found by using the I/O Docs:
// https://constantcontact.mashery.com/io-docs
lists.Add("LIST_ID");

// Next we will specify the columns that we want to import. A list of column names can be found here: 
// http://developer.constantcontact.com/docs/bulk_activities_api/bulks-activities-import-contacts-api.html
columns.Add("EMAIL");
columns.Add("FIRST NAME");
columns.Add("LAST NAME");

// Next, we will create a new AddContacts instance using the information generated above.
importActvity = new AddContacts(contactsToAdd, lists, columns);

try {
    // And lastly, we will send the bulk activity to Constant Contact.
    activityService.CreateAddContactsActivity(importActvity);
    System.Console.WriteLine("Activity Started, press any key to exit.");
} catch (CtctException ex) {
    // If there is an error, print the exception message to the console.
    System.Console.WriteLine(ex.Message);
}

If you have any questions, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Solution Provider

Re: add contacts in bulk

Hello,

 

What does CreateAddContactsActivity(importActvity) returns??

Highlighted
Solution Provider

Re: add contacts in bulk

Hello,

 

From where i can get all columns name which i want to import for contact??

 

Below like is not available which you have suggested for such :-

http://developer.constantcontact.com/docs/bulk_activities_api/bulks-activities-import-contacts-api.h...

 

Also, How can i get the count of success and failure of import contact in bulk??

 

Thank you.

Highlighted
Honored Contributor

Re: add contacts in bulk

Hello,

 

The CreateAddContactsActivity() method returns an Activity object which contains information about the Asynchronous activity that has been started. For example, you could get the status of (and other information about) the activity by calling:

activityService.GetActivity(ActivityObject.id);

You can get a list of the columns here: http://developer.constantcontact.com/docs/bulk_activities_api/bulk-activities-import-contacts.html

 

The information about success and failure counts is included in the details from the GetActivity call above. That method will also return an Activity object, which you can find the structure of here: https://github.com/constantcontact/.net-sdk/blob/master/CTCTWrapper/Components/Activities/Activity.c...

 

Please let me know if you have any questions!

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Solution Provider

Re: add contacts in bulk

Hello,

How i can obtain Access Token based on Constant Contact Username and Password through .Net SDK ??

Is their any method available for such??

 

 

Thank You.

 

Highlighted
Honored Contributor

Re: add contacts in bulk

Hello,

 

Are you building an integration that will connect to many Constant Contact accounts, or will it be for a single account?

 

If you are building for many accounts, you will need to implement to OAuth flow. You can find some examples of the flow in the sample apps included with the SDK. If those are not descriptive enough, I may be able to create a more specific sample for your use case.

 

If you are building for a single account, then you can get an Access Token for that account here: https://constantcontact.mashery.com/io-docs. Just input your API key and then click on the Get Access Token button and log in to the desired Constant Contact account. Once you have your token, you can store it in an application configuration.

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Solution Provider

Re: add contacts in bulk

Hello,

 

Yes, I'm  building an integration that will connect to many Constant Contact accounts.

 

Can you please provide me a more specific sample code (.Net SDK) for such??

 

Thank you.

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