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.

401 error with SiteVisitor API

New Member

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,""); // 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

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

Re: Hi Martin, I ran your code

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


Re: Hi Martin, I ran your code

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

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