cancel
Showing results for 
Search instead for 
Did you mean: 

Using APIs in code

Member

Using APIs in code

Hello,

 

We had success running an API from the: Constant Contact v2 API Tester/debugger  (to list our email campaigns). 
When we try and run this in a program (ASP.net  VB), we get a 401 unauthorized error.

 

When sending APIs within a program, do we first need to send something that submits our credentials (username and password).

Or would this be included in the API GET?
This is our first attempt with Constant Contact, so any information would appreciated.

Thanks 

4 REPLIES 4
CTCT Employee

Re: Using APIs in code

Hi,

 

The most common reason for getting a 401 error is not including an API Key at the end of the URL you're calling. Can you confirm you're sending all of this information in the API call?

 

https://api.constantcontact.com/v2/...?api_key=xxxxx

 

Headers:

Content-type: application/json

Authorization: Bearer yourAccessToken

 

If you do think you're sending all of that, could you send me full URL (including the API Key) you're sending a request to, along with your request headers, to webservices@constantcontact.com?

 

Thanks!

 

Best Regards,

Shannon Wallace

Partner API Support Engineer

Occasional Contributor

Re: Using APIs in code

Thanks Shannon,

 

Yes we sent it with the API_Key. I will send you what we used.

The other areas you listed:  Headers: Content-type: etc.  How do those come into play?  Are these areas in code that need to be defined?

 

When I run the API in: Constant Contact v2 API Tester/debugger, if I don't supply the Access Token I get an error. :

"error_key": "http.status.unauthorized",
   
"error_message": "No authentication is present.".   But once I enter the Access Token it runs succesfully.

So could something simular be happening on the code side?  Is there any sample code on the site that shows how to run a Get via code (VB.net)?

Thanks

CTCT Employee

Re: Using APIs in code

Hi Mike,

 

I sent you an email about this, but just for others who may come across this post in the future, not sending the access token either in the header of the request, or in the URI would have been causing the 401 error. A missing API Key, which should be appended to the URI, could have also caused this, but you were clearly sending the API Key in the URI.

 

As for the VB question, people can use the , but the examples are written in C# and would thus need to be translated into VB if that's your preferred language.

 

Best Regards,

Shannon Wallace

Partner API Support Engineer

Occasional Contributor

Re: Using APIs in code

Thank you Shannon.