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.

Authentication Problems

Highlighted
Regular Visitor

Authentication Problems

Using the ctct php library provided from Constant Contact and changing out all improtant authentication information, I recieve this error: OAuth Exception: Username <UserName> not found in datastore. I have confirmed that the API key information created for this account is correctly entered. The following is a code sample of what I have:

 

<h2>Add Contact Form Example</h2>
<?php
session_start();
include_once('../ConstantContact.php');
$username = '<UserName>';
$apiKey = 'apikey';
$consumerSecret = 'consumersecret';
$Datastore = new CTCTDataStore();
$DatastoreUser = $Datastore->lookupUser($username);

if($DatastoreUser){
    $ConstantContact = new ConstantContact('oauth', $apiKey, $DatastoreUser['username'], $consumerSecret);
    $ContactLists = $ConstantContact->getLists();
?>
<form name="addContact" action="" method="post">
    Email Address: <input type="text" name="email_address"><br />
    First Name: <input type="text" name="first_name"><br />
    Last Name: <input type="text" name="last_name"><br />
    
    <input type="submit" name="submit" value="Add Contact"><br />
</form>

<?php
    if(isset($_POST['email_address'])){
        $Contact = new Contact();
        $Contact->emailAddress = $_POST['email_address'];
        $Contact->firstName = $_POST['first_name'];
        $Contact->lastName = $_POST['last_name'];
        $Contact->lists[0] = "http://api.constantcontact.com/ws/customers/<UserName>/lists/1";
		
       $NewContact = $ConstantContact->addContact($Contact);
        if($NewContact){
            echo "<p>Thank You for joining our mailing list.</p>";
        }
    }
} else {echo '<p>Ooops, we seem to have encountered an error. Please e-mail us at <a href="mailto:&#109;&#101;&#103;&#104;&#097;&#110;&#064;&#115;&#097;&#105;&#108;&#045;&#110;&#121;&#099;&#046;&#099;&#111;&#109;" title="E-mail Classic Harbor Line">&#109;&#101;&#103;&#104;&#097;&#110;&#064;&#115;&#097;&#105;&#108;&#045;&#110;&#121;&#099;&#046;&#099;&#111;&#109;</a></p>';}
?>

 

 The UserName string is the actual user name of the account. Please help!

4 REPLIES 4
Highlighted
Regular Visitor

Re: Authentication Problems

Is there a way to add a user to a datastore that I may have missed in the setup instructions?

Highlighted
Moderator

Re: Authentication Problems

The datastore option of the library is a stub that is intended to be implemented by the user of the library.  The OAuth authentication flow will work and provide you with a token for access. If you do not implement code to store that token and username somewhere locally after you receive it, you will not be able to retrieve it at a later date for future calls.  If you look at the code for datastore, you will quickly notice that there is no actual code to store and retrieve the data.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Participant

Re: Authentication Problems

I have the same problem although I am using basic authentication

 $ConstantContact2 = new ConstantContact('basic', $apiKey, $username, $consumerPassword);

 

When connecting directly here

    https://api.constantcontact.com/ws/customers/bruncon

my credentials are accepted using format APIKEY%USERNME and PASSWORD but all I am getting is

       ERROR 404 - not found

 

 

Highlighted
Moderator

Re: Authentication Problems

404 not found indicates that the resource you are attempting to retrieve does not exist.  Since your URI that you're retrieving is not one of our API endpoints, that is actually the correct response.  You will need to find an actual endpoint, such as the following, to access parts of the API:

 

https://api.constantcontact.com/ws/customers/{username}/contacts

 

That would pull in the Contacts collection for the account {username}. 

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
Featured