cancel
Showing results for 
Search instead for 
Did you mean: 
Constant Contact wants to help you succeed! We’re celebrating our professional service programs on the Constant Contact Community this month and you have a chance to try one of the services for free! Learn more.

Adding multiple contacts in the contact List

SOLVED
Occasional Advisor

Adding multiple contacts in the contact List

I was just following steps given in the link

http://community.constantcontact.com/t5/Documentation/Creating-an-Add-Contacts-Remove-Contacts-Activ...

 

But these are not clear.

I tried to post the string through curl.

First thing I wanna to ask is what is SV_ADD

second, What is the these string meant for:

activityType=SV_ADD
&data=Email+Address%2CFirst+Name%2CLast+Name%0A
wstest3%40example.com%2C+Fred%2C+Test%0A
wstest4%40example.com%2C+Joan%2C+Test%0A
wstest5%40example.com%2C+Ann%2C+Test
&lists=http%3A%2F%2Fapi.constantcontact.com%2Fws%2Fcustomers%2Fjoesflowers%2Flists%2F2
&lists=http%3A%2F%2Fapi.constantcontact.com%2Fws%2Fcustomers%2Fjoesflowers%2Flists%2F5

 

Where i have to use this as it's document is not clear. If there is any other Documentation please let me know.

M trying to embed through php code.

24 REPLIES 24
CTCT Employee

Re: Adding multiple contacts in the contact List

Hi,

 

Sorry you're not finding the documentation to be clear.

 

SV_ADD is the type of account activity you are creating in your account when you do the POST.  (I believe it was meant to stand for Site Visitor Add, as in adding contacts).

 

The string is the encoded data that you are sending to us through the API.  In the example below, you set the data columns to include email address, first name, and last name.  After that, you are putting in as many contact entries as you want, including their email, first and last name.  Lastly, you are selecting which contact lists in your account they are being added to (all contacts will be added to all lists included).

 

I hope that clarifies things!  Thank you for contacting Constant Contact, and have a wonderful day!

 

Best Regards,

Shannon W.

API Support Specialist

Occasional Advisor

Re: Adding multiple contacts in the contact List

I don't want to submit form,

 

This is through cron, is it possible to implement through ph cron system.

Can i get any sample code? because there is not given any activity sample code. so can you help me out in this.

CTCT Employee

Re: Adding multiple contacts in the contact List

Hi,

 

Yes, it would be possible to set this up with a cron script, but we don't have any specific examples of that.  Below is a PHP script that does a bulk contact add using acitivities--you will just need to add your authentication to it and specify the file path for your csv file and the list number you want the contacts added to.

 

<?PHP
set_time_limit(0);
require 'ConstantContact.php';

###Fill out this information!###
$listNumber = 1;
$FILENAME = "./temp/filename.csv";

// Authentication to Constant Contact

//You shouldn't have to edit anything below this line, unless you have a file with greater than 60,000 rows


// Set row value
$row = 1;

// Start the URI of which to pass to bulk activities
$BeforeEmailAddress = "activityType=SV_ADD&data=Email+Address";

// set value of totalContacts
$totalContacts = 0;

// Used for to pass in the column number for large CSV 
// You may want to remove this depending on your integration

$x = $_GET['x'];

if (($handle = fopen("$FILENAME", "r")) !== FALSE) {
	
	// itterate through rows
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    	// how many columns are in a row
        $num = count($data);
        
        // use echo for testing
        //echo "<p> $num fields in line $row: <br /></p>\n";

        $row++;
        // $c = 0 if your not using X;
        // data[0] is your first column, this needs to contain your email address
        for ($c=$x; $c < ($x+1); $c++) {
          echo "<b>$c</b><br>";
                // Checks for value of "x" as this meant that the contact
                // belongs to the current column list
	
        	if ($data[$c] == $x && $totalContacts < 20000) {
        		$emailAddress .= "\n" . $data[0];
        		$totalContacts++;
                // Bulk activities have a limit of 20k contacts you must have more than 20 contacts
                // to submit the contacts via bulk activity

                // if contacts are over 20k then you need to start a new activity
        	}else if($data[$c] == $x && $totalContacts >= 20000 && $totalContacts < 40000){
        		$emailAddress2 .= "\n" . $data[0];
        		$totalContacts++;
        	}else if($data[$c] == $x && $totalContacts >= 40000){
        		$emailAddress3 .= "\n" . $data[0];
        		$totalContacts++;
        	}

        }
        
    }

    $lv = $listNumber; 
    $list = "http://api.constantcontact.com/ws/customers/$username/lists/".$lv;
   
    fclose($handle);
}
// Echo's the string to verify that you are targeting the correct information to the correct list
echo $BeforeEmailAddress.urlencode($emailAddress)."&".urlencode($list);
 
        // Remove below echo statement to make this script active, always test as your contacts may go to the wrong list

	$ConstantContact->bulkAddContacts($BeforeEmailAddress.urlencode($emailAddress)."&lists=".urlencode($list));
	
        // Start second bulk load activity if more than 20k contacts existed.

	if(isset($emailAddress2))
	{
		$ConstantContact->bulkAddContacts($BeforeEmailAddress.urlencode($emailAddress2)."&lists=".urlencode($list));;
	}
	if(isset($emailAddress3))
	{
		$ConstantContact->bulkAddContacts($BeforeEmailAddress.urlencode($emailAddress3)."&lists=".urlencode($list));;
	}

// Tells you how many contacts were uploaded to which list id.
echo "<br>".$totalContacts . " Have been uploaded to " . $list;
?>

 

 

I hope that helps. Have a great day!

 

Best Regards,

Shannon W.

API Support Specialist

Occasional Advisor

Re: Adding multiple contacts in the contact List

Hi,

 

After getting you reply I found that the class which m using is in cc_class.php. And the file which you included in ConstantContact.php. Is m using old class???

In my class I have to pass only username,password,secret key.

 

But with Constantcontact it ask for oauth. it redirects me to constant contact site ask me to login then after redirect me back to previous page. but I don't want to authenticate after getting onto your site. Is it possible.

 

And the class which you had given having large number of functions they will definetly help us out but now issue is with authenticate.

Occasional Advisor

Re: Adding multiple contacts in the contact List

Hi,

 

Even after authentication it gives me this error.

 

Fatal error: Call to a member function xpath() on a non-object in E:\xampp\htdocs\constant\dti\campaign\wrapper\Components.php on line 1427

 

I didn't tweaked anything in core files. can you help me out what's this error due to????

CTCT Employee

Re: Adding multiple contacts in the contact List

Hi,

 

Could you replace the contents of your Components.php file with the code found on this page in our PHP Wrapper library?  I just want to make sure you have the most recent version.

 

Thanks!

Shannon

Occasional Advisor

Re: Adding multiple contacts in the contact List

I updated the file but still same error.

at that line i am having same code.

 

public static function findNextLink($item){
$nextLink = $item->xpath("//*[@rel='next']");
return ($nextLink) ? (string) $nextLink[0]->Attributes()->href : false;
}

Occasional Advisor

Re: Adding multiple contacts in the contact List

hi shannon,

 

I think upgradation work. but to send code for authentication is not good as I don't want to authanticate with login. So can you tell how can I modify the code of this class CTCTDataStore. according to me with this this class i can get it done right????

CTCT Employee

Re: Adding multiple contacts in the contact List

Hi,

 

That's good news.  You could technically use basic authentication, but I would recommend going through the OAuth 2 flow since we will be discontinuing support for basic authentication and applications using basic authentication will fail when that happens (in the next year or so).  With OAuth 2, you need to authenticate an account only once, then you get an access token that doesn't expire.  You can then use that access token in the future.

 

Here is an example of how to do Oauth 2 simply.

 

Best Regards,

Shannon W.

API Support Specialist