cancel
Showing results for 
Search instead for 
Did you mean: 
Constant Contact wants to help you succeed! We’re celebrating our professional service programs on the Constant Contact Community this month and you have a chance to try one of the services for free! Learn more.

401 error

Occasional Participant

401 error

I am trying to access the API using the API Key and Token via the .NET wrapper. 

 

string token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
string apiKey = "xxxxxxxxxxxxxxxxxxxxxxxx";

 

var constantContact = new ConstantContact(apiKey, token);
var acctInfo = constantContact.GetAccountSummaryInformation();

 

An exception occurs in GetAccountSummary with the message 401 unauthorized. I also receive the 401 unauthorized when I try sending a request  with the API Key and Token using Fiddler.Using the same API Key and Token, I can successfully access the API using the IO Docs.

 

What am I doing wrong?

 

Thanks!

 

5 REPLIES 5
Honored Contributor

Re: 401 error

Hello,

 

When you are receiving a 401 error, that means that the authentication has failed due an invalid access token being provided. The quickest way to test this would be to use the IO docs to generate a new access token with your API key and see if the new token resolves the issue.

 

If re-generating the token does not solve the problem, I would suggest sending us an email and including both the API key and the access token so that we can look into what is happening. We can be reached by email at webservices@constantcontact.com

 

Sincerely,

Elijah G.
API Support Engineer
Occasional Participant

Re: 401 error

I was unable to regenerate a new access token for my API key, so I created a new API key. This did not resolve the problem I'm having. I will send an email with my information.

 

Thanks!

CTCT Employee

Re: 401 error

Hi Stacie,

 

I responded to your email. It looks like the access token value was just being stored in a different variable than you were using when calling one of the methods (thus, the access token wasn't being passed to us). I hope it was just that simple!

 

Best Regards,

Shannon Wallace

Partner API Support Engineer

Occasional Participant

Re: 401 error

I double checked my code and all I see is the variable called "token", which is being passed into the constructor when initializing a new instance of the ConstantContact class.

 

The only place I found a variable called "accessToken" is in the ConstantContact .NET wrapper that I downloaded from GitHub. Are you suggesting that I need to call a different method in the .NET wrapper that accepts the API key and token as parameters?

 

Thanks!

Honored Contributor

Re: 401 error

Hello,

 

You are correct that the Access Token is to be provided when you are creating an instance of the ConstantContact class. If you are receiving a 401 error, that indicates that the API is not receiving a valid Access Token and is not able to grant you access. It is important to note that an Access Token should be generated for each combination of an API key and Constant Contact account.

 

The easiest way to generate an Access Token for use with a Constant Contact account is to navigate to https://constantcontact.mashery.com/io-docs, fill in your API key, and click on Get Access Token. You will be able to select "I already have an account" and log in to the desired Constant Contact account. Once you grant access to your application, you will be given an access token for that account.

 

If there is any additional information that I can provide, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer