Between 8:00 - 9:00 am ET on 10/25 we need to take our site down to make updates. We recommend logging out before 8:00am ET and not using your account during this time. Thank you for your patience while we make these important updates.

401 error with SiteVisitor API

Participant

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)));

    array_push($lists,LIST);



    $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

    curl_close($ch);



// Create an array of the response values

    array_push($details,explode("\n",$cc_result));


 


thanks,


Martin


 

Martin

3 REPLIES 3
Moderator

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