cancel
Showing results for 
Search instead for 
Did you mean: 
Due to an issue with YouTube, inserting videos in your emails is showing an error. Until they are able to resolve this issue, we recommend using a different video hosting service. We will continue to monitor this outage and update you as we have more information.

How to make simple API call to post an email?

Highlighted
Regular Visitor

How to make simple API call to post an email?

I've scanned through the v3 API docs a number of times but the authentication flows don't really seem to fit my very simple use case. The docs reference a "redirect URI" and "granting access to an application", but in this case I am the user / application and I just want to insert an email into Constant Contact via API call.

 

I have an email (received via form on my site) and I simply want to make a POST request to add this email to constant contact.

 

I have my API key and a secret, so can anyone tell me (or better yet, post a code snippet) the way to format an HTTP call to post an email? The part I seem to be stuck on is generating the access token.

 

Can I generate an access token once to be used at my server to authenticate calls to the CC API?

 

Thank you.

3 REPLIES 3
Moderator

Re: How to make simple API call to post an email?

Hello @ericg5327,

 

Thank you for reaching out to Constant Contact's API Support.

 

You mention that you are stuck on generating the Access Token. When using our v3 API you do need to go through the oAuth flow, either client or server, to generate an Access Token. Even if you are the user this process is still required. The Access Token is what identifies which Constant Contact account you want to send data to and receive data from.

 

Once you have established that portion of your program you can then create your email. You can see a code sample of a POST on this page.


Regards,
Jimmy D.
Tier II API Support Engineer
Tags (1)
All Star

Re: How to make simple API call to post an email?

I am looking to do the same thing.  The link you gave on how to setup authorization is very ambiguous.  For example, I am going through the client route (request to the API will be coming from JS).  The page says I need to send an authorization request, but where do you send this request to?  There is no URL referenced.  Also, when you try Googling anything related to Constant Contact's API, you get a bunch of links that reference the V2 build.

All Star

Re: How to make simple API call to post an email?

This is what my current request looks like with jQuery's ajax() method:

 

type: 'POST',
url: 'https://api.cc.email/v3/contacts',
beforeSend: function(request) {
request.setRequestHeader('Authorization', 'Bearer {access_token}');
request.setRequestHeader('Postman-Token', 'akdslfjasf-adfkdf-42d-924-e9843168744');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Accept', '*/*');
request.setRequestHeader('cache-control', 'no-cache');
},
data: {
email_address: {
address: 'sandman@gmail.com'
}
},

 

For the headers, I copied what was listed in the example at https://v3.developer.constantcontact.com/api_guide/email_campaign_create.html?_ga=2.235470849.128746....

 

For the "Postman-Token" header, I am using the "API Key" value associated with my registered app.  From the sounds of it, it seems this isn't enough.  I need to first hit an authorization server which should then return another token, but the article you linked to doesn't provide enough info on how to do this.