How I can add bulk contacts using new version oauth2.0

Regular Participant

How I can add bulk contacts using new version oauth2.0

Hi I want to add bulk contact. M using oauth2


In constantcontact.php there is a function name addCreateContactsActivity

So how to use this function as it's second parametere is of AddContact class. So m not getting it how to pass values of users in it?



Thank for the help in advance!!


While our SDK doesn't have a service directly for adding bulk contacts, this can be done. Please take a look at the following code to see how to create an array of contacts, assign them column names, and use the addCreateContactsActivity. 


<title>Constant Contact API v2 Bulk Add Contacts Sample Code</title>

    // --- Setup ---
    // require the autoloader
    require_once 'php-sdk-master/src/Ctct/autoload.php';
    // Set up our use statements for the components we are using
    use Ctct\ConstantContact;
    use Ctct\Components\Contacts\CustomField;
    use Ctct\Components\Contacts\Contact;
    use Ctct\Components\Contacts\Address;
    use Ctct\Exceptions\CtctException;
    use Ctct\Components\Activities\AddContacts;
    use Ctct\Components\Activities\AddContactsImportData;
    // Enter your Constant Contact APIKEY and ACCESS_TOKEN
    define("APIKEY", "API_KEY");
    // Create an instant of the Constant Contact Class
    $cc = new ConstantContact(APIKEY);
    // --NEW--
    // Define an array of contacts to import
    $contacts = Array();
    try {
    // --- Defining a contact to import ---
    // Create an instance of the AddContactsImportData class
    $contact = new AddContactsImportData();
    // Next we will populate this with data. For this sample I am defining a value for each of the 15 custom fields and an email address.
    // For more information about what fields you can set on this class, you can review src/Ctct/Components/Activities/AddContactsImportData.php
    // This example only loads a single contact, but you could loop over the code to define multiple contacts.
    $contact->addCustomField(CustomField::create(array("name"=>"Custom Field 1","value"=>"CF1")));
    // --NEW--
    // Add the contact we just created to the array of contacts.
    $contacts[] = $contact;

    // Once we have our contact data, we need to construct an array of column names. These can be found in the documentation for
    // bulk uploads here:
    $columns = Array(
                     "CUSTOM FIELD 1"

    // Next you need to define an array of strings that contains the IDs of each list you wish to add these contacts to.
    $lists = Array(
    // The last step before we send it to Constant Contact is to create an instance of the AddContacts wrapper class to contain all of the information about this import.
    $contactImport = new AddContacts($contacts,$lists);
    $contactImport->column_names = $columns;
    // Finally, you can send the import to Constant Contact.

    echo "Activity Created!";
    } catch (CtctException $e) {
        echo "An Error was encoutered: " . print_r($e->getErrors(),true);
Developer Portal

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

Visit Page