User name/password not working

Regular Participant

User name/password not working

I'm having trouble getting out of the gates -- I read the docs, downloaded the sample php docs, changed the constants to my own api key, user name, and password, uploaded them to my site... and can't get my username/password to work.

When I try to log in on the index page of the sample php scripts (it goes to getLists.php), I get a 401 error.

When I try to go straight to a page such as http://api.constantcontact.com/ws/customers/my_username/lists , it won't accept my username/password.

I've quadruple checked my api key, username and password, and I've definitely not mistyped them or anything. Any idea what I'm doing wrong?
10 REPLIES 10
Frequent Participant

The most common problem is mixing up *which* username and password to use. The username (my_username) to use is the username for your Constant Contact account (http://www.constantcontact.com) - not the username and pwd you use to login to this developer web site.

If you have that right, the second most common problem is that the username is not properly constructed for DIGEST AUTHENTICATION. See this page and specifically, this part of that page:

...will need to construct a HTTP Username from a concatenation of your API User Key, the "%" character and the Constant Contact customer's UserName. This information is passed with Constant Contact Customer's Password in the HTTP Header and the HTTP library should manage the details.

If neither of those two things work, perhaps there is something highly unusual about your username or password?
Thanks,
Tom M
Group Product Manager – Content Editing
Constant Contact
Regular Participant

Still no luck -- on the php sample page: still a 401 error.

At

http://api.constantcontact.com/ws/customers/my_api_key%my_username/lists

I get: 400 Bad Request.

Nothing unusual with the user name or password. Originally the password had an ampersand in it, but I got rid of it.
Frequent Participant

The URI should be:
http://api.constantcontact.com/ws/customers/my_username/lists

The HTTP Username should be:
my_api_key%my_username

The HTTP Password should be:
my_Password

(For a quick test, you should be able to enter the URI into a browser and have the browser try and load that URI. You should receive a dialog requesting your login credentials. Input the username (constructed as above) into the username box and your password into the dialog and you should get a legible response. I just did this for my API key and username / pwd from FireFox).

Thanks,
Tom M
Group Product Manager – Content Editing
Constant Contact
Regular Participant

Thanks very much -- okay, the browser test works as above.

Still getting stuck on the php sample code. Here are the constants settings in Constants.php:

define("PARAM_NAME_API_KEY", "my_api_key");
define("PARAM_NAME_USER_NAME", "my_user_name");
define("PARAM_NAME_PASSWORD", "my_password");
define("HOST", "api.constantcontact.com");
define("URI", "http://api.constantcontact.com");
define("LOCAL_BASE_URL", "http://localhost/");

I've also tried using the concatenated version for PARAM_NAME_USER_NAME, and also entered both the concatenated and unconcatenated usernames in the form for both versions. Still getting 401 error.

I also tried changing "localhost" to the actual URL of my site.
Frequent Participant

PARAM_NAME_USER_NAME in the constants .php file should be just your Constant Contact username. (The script builds credentials from API Key and UserName). Also provide your constant contact password and your API key in that constants file. The other values should be fine.

I haven't run that script you are running, but
1) You do not need to include your API key in the username field - just the username
2) You should initially try this with the same username/pwd you put into the Constants file.


Finally, the example you are working from is focused on bulk submission of contacts. If you are just looking to add one conctact at a time (ie. replace the Join My Mailing List), then you should focus on the Contacts Collection Resource (these sample scripts focus on the Activities Collection).
Tom M
Group Product Manager – Content Editing
Constant Contact
Regular Participant

I got the sample scripts to work. There are some errors in them:

In Functions.php and getLists.php, the constants are in the request variables, and that's why the scripts don't work.

In Functions.php, instead of:

$userNamePassword = $_REQUEST . '%' . $_REQUEST . ':' . $_REQUEST;

it needs to be:

$userNamePassword = PARAM_NAME_API_KEY . '%' . PARAM_NAME_USER_NAME . ':' . PARAM_NAME_PASSWORD;

And in getLists.php, instead of:

$xml = executeRequest(URI . '/ws/customers/' . $_REQUEST . '/lists');

it needs to be either:

$xml = executeRequest(URI . '/ws/customers/' . PARAM_NAME_USER_NAME . '/lists');

or:

$xml = executeRequest(URI . '/ws/customers/' . $_REQUEST . '/lists');

(I think the latter is more appropriate since this is an authentication form.)

If you make the above changes, these sample scripts work fine. Otherwise, no go. I haven't checked the other scripts in the php samples, but I fear that the same mistakes might be in them too.

Thanks for your help on this -- and yes, I understand that these functions are not what I need for my project -- I was just trying to get them to work as an exercise in understanding how the the API works.
Regular Participant

Thank you for showing us this possible problem with the PHP Example code. I will look into the code and make sure the PHP Example code is working as designed. If not I will make necessary changes.

Mike C Support Engineer, Constant Contact

Regular Participant

I was unable to recreate your issue. My understanding of the code is as following.

PARAM_NAME_API_KEY, PARAM_NAME_USER_NAME, and PARAM_NAME_PASSWORD is define as a Constant String in Constants.php
The Value of PARAM_NAME_API_KEY equals to "api_key"
The Value of PARAM_NAME_USER_NAME equals to "site_owner_user_name"
The Value of PARAM_NAME_PASSWORD equals to "sopassword'

This means that this code in GetList.php

$xml = executeRequest(URI . '/ws/customers/' . $_REQUEST . '/lists');

would give you the same results as this code

$xml = executeRequest(URI . '/ws/customers/' . $_REQUEST . '/lists');

Also this code in Functions.php,

$userNamePassword = $_REQUEST . '%' . $_REQUEST . ':' . $_REQUEST;

would give you the same results as this code

$userNamePassword = $_REQUEST . '%' . $_REQUEST . ':' . $_REQUEST;


This should not have worked for you in Function.php

$userNamePassword = PARAM_NAME_API_KEY . '%' . PARAM_NAME_USER_NAME . ':' . PARAM_NAME_PASSWORD;

If you echo $userNamePassword after using the above you would get this string
"api_key%site_owner_user_name:sopassword"

It would not echo your actual API Key, Username or Password, but rather the names of the variables you are using

Mike C Support Engineer, Constant Contact

Regular Participant

The problem is that $_REQUEST only retrieves the variables $_GET, $_PUT, or $_COOKIE, which are not the same as the constants.

For example, if my site user name is joesgarage, $_REQUEST is really $_REQUEST. But there is no $_REQUEST. There is $_REQUEST, and there is PARAM_NAME_USER_NAME, both of whose correct value should be 'joesgarage'. Big difference.

In other words, both $_REQUEST and PARAM_NAME_USER_NAME equal 'joesgarage', but $_REQUEST does not -- in fact, it doesn't even exist.

So if your script calls $_REQUEST, it looks for $_REQUEST, which it cannot find.

If your script calls $_REQUEST, it finds it with the value 'joesgarage' (assuming that it was entered into the form field), which is correct, and authenticates the login.

If it calls PARAM_NAME_USER_NAME, it also finds 'joesgarage'.
Regular Participant

I think the misunderstanding with Constants.php file. Let say my api_Key = 123345abc and let take a look at one line of code in Constants.php file.

define("PARAM_NAME_API_KEY", "api_key");

After this line of code

PARAM_NAME_API_KEY = "api_key"

Not "123345abc"

$_REQUEST is the same as $_REQUEST

if you echo PARAM_NAME_API_KEY you will get api_key
if you echo $_REQUEST you will get 123345abc
if you also echo $_REQUEST you will get 123345abc

Mike C Support Engineer, Constant Contact

Developer Portal

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

Visit Page