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.

Difficulties authenticating

Highlighted
Occasional Contributor

Difficulties authenticating

I need to create a script that will run via cron a couple times per day to aggregate opt-in email addresses from various sign-up forms and membership databases on our website. The script should rarely, if ever, be used in a browser. To start with, I'm trying to use Shannon's examples as described here: http://community.constantcontact.com/t5/Developer-Support-ask-questions/Error-400-from-Constant-Cont... Sadly, all I get when loading up the page is... Constant Contact HTTP Request Exception: HTTP Status 401 - An Authentication object was not found in the SecurityContext ...followed by a lot of PHP errors. How can I actually get this thing to authenticate?
5 REPLIES 5
Highlighted
Employee

Re: Difficulties authenticating

Hi,

 

I posted that example before the new API came out, but for a longer shelf life, I'd recommending developing on the V2 API now.  There is a contact form example here (you can get rid of the html code and just use the PHP if that's all you need.  You'd need to download the php-sdk in its entirety, and then in the example file, enter your api key and access token on lines 27 and 28 to get up and running.  Let us know if you have any trouble!

 

Best Regards,

Shannon W.

API Support Specialist

Highlighted
Occasional Contributor

Re: Difficulties authenticating

Hi Shannon,

 

Thank you for your reply.  Unfortunately, I'm running into one PHP error after another with the current SDK.

 

Upon loading up addOrUpdateContact.php for the first time, I got the following error:

 

Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /path/to/examples/addOrUpdateContact.php on line 20


So I added double quotes to each of the "use" lines, like so:

 

use "Ctct\ConstantContact";
use "Ctct\Components\Contacts\Contact";
use "Ctct\Components\Contacts\ContactList";
use "Ctct\Components\Contacts\EmailAddress";
use "Ctct\Exceptions\CtctException";

 

That resulted in the following error:

 

Fatal error: use: Not yet supported. Please use include_once() or require_once() in /path/to/examples/addOrUpdateContact.php on line 20

 

So I switched "use" to "require_once" in all of the above lines, and got the following warnings and errors:

 

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /path/to/src/Ctct/autoload.php on line 5

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /path/to/src/Ctct/autoload.php on line 5

Parse error: syntax error, unexpected T_STRING in /path/to/src/Ctct/autoload.php on line 5

That's when I decided to stop and ask for help. ;)

 

I expected the sample code to more or less work out of the box, but they're not sure working for me.  Any ideas on how to get past these errors?

 

Thanks,

 

Matthew

Highlighted
Occasional Contributor

Re: Difficulties authenticating

Forget everything I posted above, it turns out we didn't have the correct PHP version.  I upgraded to 5.3 and the PHP errors have basically disappeared, except that I now get the following error at the top of the page when loading addOrUpdateContact.php:

 

Array ( [error_key] => mashery.not.authorized.inactive [error_message] => The Mashery account associated with this request is not active, or an invalid API key was used. )

 

Result is that the lists dropdown won't populate and the add form doesn't work.

 

Please let me know how to proceed.

 

Thanks again,

 

Matthew

Highlighted
Employee

Re: Difficulties authenticating

Hi Matthew,

 

Sorry for the trouble.  There are a couple of things to check.

 

1.  In the addOrUpdateContact example file, did you enter your API key on line 27 (and your access token on line 28)?  It should look like this.  Verify that there are no spaces within the quotes that define your api key.

 

// Enter your Constant Contact APIKEY and ACCESS_TOKEN
define("APIKEY", "xxxxxxx");//where xxxxxxx is your api key
define("ACCESS_TOKEN", "yyyyyyyy"); //where yyyyyyyy is your access token

 

If your API Key has dashes in it, that means that you are trying to use a V1 (non-Mashery) API Key with a V2 library, which won't work.  Steps 1 & 2 on this page describe how to generate a Mashery API Key.

 

2.  Your Mashery API Key, for some reason, isn't active.  If you select standard API Key access, your key should be active immediately.  If you select partner API Key access, we have to approve it after verifying that you are a Constant Contact partner.  I would recommend logging into Mashery to make sure your API Key displays as active (not waiting or disabled).

 

If you think your API Key is active and entered correctly in the example script, feel free to email your API Key to webservices@constantcontact.com, and reference this post.

 

Best Regards,

Shannon W.

API Support Specialist

Highlighted
Occasional Contributor

Re: Difficulties authenticating

Thanks Shannon, that did it.  I have a very basic script working, so this thread appears to be resolved.

 

That said, I'm still having some issues and would very much appreciate it if you could help me figure this one out:

 

http://community.constantcontact.com/t5/Developer-Support-ask-questions/Add-contact-to-multiple-list...

 

Thanks again!

 

Matthew

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