Javascript and cross-domain problems

SOLVED
Highlighted
Occasional Contributor

Javascript and cross-domain problems

Assuming I manage to authenticate and get the username, and have everything I need to start accessing the API. 


Is it possible to do access the API with javascript? Or would it be halted by the same origin policy / cross site call problem?

 

I've read JSONP can provide a workaround, but is it possible to use Ajax and JSONP with CC to successfully avoid all server-side programming? 

If JSONP doesent work(and it seems that it at best works only for GET requests), is there another way to solve it?
Or am I pretty much forced to use some server-side  programming?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Javascript and cross-domain problems

You are correct, there is no way to access a REST API through JavaScript.  The JSONP workaround is possible if the API in question is specifically designed to support JSONP, which the Constant Contact API is not.  We do provide wrapper libraries in PHP, C# and a few other open source wrappers.  It's definitely possible for you to implement those wrappers and return to yourself a JSON object, which you can then use via JavaScript requests in an AJAX style, even though the requests are being processed on your server behind the scenes.

Dave Berard
Senior Product Manager, Constant Contact

View solution in original post

7 REPLIES 7
Highlighted
Moderator

Re: Javascript and cross-domain problems

You are correct, there is no way to access a REST API through JavaScript.  The JSONP workaround is possible if the API in question is specifically designed to support JSONP, which the Constant Contact API is not.  We do provide wrapper libraries in PHP, C# and a few other open source wrappers.  It's definitely possible for you to implement those wrappers and return to yourself a JSON object, which you can then use via JavaScript requests in an AJAX style, even though the requests are being processed on your server behind the scenes.

Dave Berard
Senior Product Manager, Constant Contact

View solution in original post

Highlighted
New Member

Re: Javascript and cross-domain problems

I am stuck with the same issue..could you please help in solving the issue

Highlighted
New Member

Re: Javascript and cross-domain problems

@Minum:
I basically gave up.
I don't know if Constant Contact have modified their API since I tried this,

but basically, it is IMPOSSIBLE to send http-requests to foreign URLs from javascript, unless the sites you want to request(in thsi case Constant Contacts API), contain built in support for CORS and/or JSONP.

 

So, bottom line is, unless Constant Contact have modifeid their API to use CORS, you have two options: 1) Give up. 2) Use some server-side code like C#, PHP etc instead of client-side javascript.

Highlighted
Moderator

Re: Javascript and cross-domain problems

At this time we have no plans to support JSONP but we are currently looking into the security and feasibility of CORS.  I don't have an ETA on that investigation but once our security team completes their assessment, I will update on if we are or are not going to be releasing support for CORS. 

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
New Member

Re: Javascript and cross-domain problems

Any progress with CORS?

Highlighted
Honored Contributor

Re: Javascript and cross-domain problems

Hello,

 

Based on the feedback from our security team, there are some significant hurdles in the way for us in implementing this functionality for our APIs. Because of this, we are currently not setting any timelines for adding this, and continuing to listen for feedback from our developer community. 

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
New Member

Re: Javascript and cross-domain problems


corsmonster.jpeg
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured