activecampaign-api-nodejs icon indicating copy to clipboard operation
activecampaign-api-nodejs copied to clipboard

CORS problem

Open JulieVoltaire opened this issue 3 years ago • 9 comments

Hi,

I do a GET request on my Vuejs app (localhost:8080) and have some CORS problems : "Access to fetch at 'my_url/admin/api.php?api_key=my_key&api_action=contact_view_email&api_output=json&[email protected]' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."

I have the same problem when I use a simple fetch instead of your library.

How can I manage CORS?

Thanks for your help

JulieVoltaire avatar Nov 03 '20 13:11 JulieVoltaire

I am facing the same issue. @JulieVoltaire Did you find a fix for this?

CP-4 avatar Feb 24 '21 11:02 CP-4

I'm new here, but this looks like a backend API. Are you trying to use it from the front-end? If so, this is the error I would expect.

sampl avatar Mar 23 '21 17:03 sampl

anyone got a solution to making calls to the api from client-side?

dionkas avatar Sep 12 '21 11:09 dionkas

Same error here. Trying to use the JavaScript SDK as per this documentation article: https://www.activecampaign.com/blog/how-to-setup-activecampaign-event-tracking#events-to-ac-using-js

fariazz avatar Feb 08 '22 03:02 fariazz

@dionkas, @CP-4, @JulieVoltaire Since the ActiveCampaign API requires that a secret key is sent in a header, you'd be exposing your secret key to all of your visitors if you made requests to the ActiveCampaign API from the client side. Anyone with this key can make a request to ActiveCampaign on your behalf, please don't do this!

@fariazz That article doesn't describe using this SDK and shows making requests to https://trackcmp.net/event which is not the URL format of the ActiveCampaign API that this SDK uses. The article is pretty old (2017), so perhaps references an older ActiveCampaign API or something.

jaydiablo avatar Apr 22 '22 23:04 jaydiablo

Thank you for clarifying @fariazz . We ended up deciding to send the data to a Zapier webhook, and let Zapier do the ActiveCampaign integration.

I think what many of us were after was the ability to use JS to send ActiveCampaign events from the client-side, in a similar way to how we send events to say Google Analytics or Mixpanel. Yes, someone can open the browser console and send events, but this would be low-impact from the business-side, and after using Google Analytics and Mixpanel for 10 years or so I've never seen this happening.

In our case, we wanted to send product usage events to ActiveCampaign, without having to develop backend modules. Simple stuff, like whether the user invited another user, or whether a user watched a video within the platform.

fariazz avatar Apr 24 '22 23:04 fariazz

@jaydiablo , so what solution do you propose to fetch data from a active campaign api without having cors issues?

ranran2121 avatar May 12 '22 20:05 ranran2121

I have the same problem (after following the same tutorial article above: https://www.activecampaign.com/blog/how-to-setup-activecampaign-event-tracking#events-to-ac-using-js) - I thought the whole point of posting something (e.g. like a form) was that it would be limited access (for e.g. the event ID has to match something that's already in AC), and thus safe. If anyone else finds a way to send events from the client-side to AC, I'd be very interested.

johnsonfung-pathstream avatar May 27 '22 01:05 johnsonfung-pathstream

Hey, there isn't a way to call the AC api from the client-side. To bypass this, I am using a proxy on my server to forward the events from the client to AC.

dionkas avatar May 27 '22 08:05 dionkas