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?
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 email@example.com
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.
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!
Partner API Support Engineer
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?
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!