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.

Using APIs in code

Highlighted
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
Highlighted
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

Highlighted
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

Highlighted
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

Highlighted
Occasional Contributor

Re: Using APIs in code

Thank you Shannon. 

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