We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

401 error with SiteVisitor API


401 error with SiteVisitor API

Hi all,

I've been using this code for a long time it worked just fine. Now i'm getting a 401 error, and I don't know why.

Can anyone help?

Here's the code:

    $data = "loginName=NAME";

    $data .= "&loginPassword=PASSWORD";

    $data .= "&ea=" . urlencode(strip_tags(strtolower($email)));


    $list_data = "&ic=" . urlencode(strip_tags($list_name));

//If the form was submitted, and the email is valid, then POST via libcurl

    $ch = curl_init();    // initialize curl handle

    curl_setopt($ch, CURLOPT_URL,"http://api.constantcontact.com/0.1/API_AddSiteVisitor.jsp"); // set url to post to

    curl_setopt($ch, CURLOPT_FAILONERROR, 1);

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects

    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable

    curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s

    curl_setopt($ch, CURLOPT_POST, 1); // set POST method

    curl_setopt($ch, CURLOPT_POSTFIELDS, $data . $list_data); // add POST fields

    $cc_result = curl_exec($ch); // run the whole process


// Create an array of the response values








Hi Martin,


I ran your code locally on my PHP server and was able to use it to add contacts to my account without issue.  The API you are using is one of our depricated older APIs which we have replaced, however it should still work for the forseeable future.  A 401 response code should not be given from this API at any point though, 401 Unauthorized is only available through our REST API.  This older API would return 400 for invalid Login Credentials and 500 otherwise.  

Dave Berard
Senior Product Manager, Constant Contact

How can i add first name last name and custom fields?

This API is depricated and no longer provided for new customers, we only allow legacy users of the API to continue to use it and are in the process of working with them to completely turn this API off.  This API does not support any suscriber demographics.  I highly recommend not using this API as it will be completely shut off in the near future.  Our existing REST API provides all of the same functionality plus the ability to manage demographics. 

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page