I have been trying to figure out how to use the bulk activities add contacts api for quite sometime now and just recently figured out how to actually do it correctly. I could find very little help with what I was doing, so I figure it might help someone with a similar problem as mine to have an example of how to use with JSON, PHP, and curl http://developer.constantcontact.com/docs/bulk_activities_api/bulk-activities-add-contacts.html with a JSON POST script. $user = '{
"import_data":[
{
"email_addresses":[
"user31@example.com"
]
},
{
"email_addresses":[
"user32@example.com"
]
}
],
"lists":[
"9"
],
"column_names":[
"EMAIL"
]
}';
$access_token = 'ACCESS TOKEN';
$url = 'https://api.constantcontact.com/v2/activities/addcontacts?api_key=API KEY';
// Start curl.
$ch = curl_init();
// Set query data here with the URL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Authorization:Bearer ACCESS TOKEN', 'Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '30');
curl_setopt($ch, CURLOPT_POSTFIELDS, $user);
$content = curl_exec($ch);
print_r($content);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_close($ch); The formatting of the JSON is very particular so I suggest you run it through http://jsonlint.com/ to be sure you are passing in a valid JSON string. Hopefully this example saves someone some time.
... View more