Skip to main content

When I try to run a get fetch request on an Event Segmentation:
https://developers.amplitude.com/docs/dashboard-rest-api#event-segmentation

I get a CORS error that blocks talking with the GET request url. Is there a solution to using the REST API above in the frontend using javascript?

Hey @gsw1 

I’m not sure if your query is related to the below post.

 @Denis Holmes will be the best person to look into this one.


Hi Saish! I don’t believe this is an issue with VPN or adblocker. I think in general browsers safeguard users with CORS by blocking sites from fetching GET requests sometimes which is why a lot of people tend to write requests in the backend.

 

I would like to do it in the frontend if it’s possible so was wondering if we can bypass this CORS issue somehow.

 

Here is the sample error I get:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at {Amplitude Segmentation URL redacted}. (Reason: CORS request did not succeed). Status code: (null).


Hi @gsw1 ,

 

Usually, as @Saish Redkar mentioned, this is often due to some Adblocker, VPN or Application/Extension that is interfering with the flow of things. This is actually quite difficult for us to debug as usually, you should be able to send events without issue. Have you tried on other wifis? Same issue? can you try it in Incognito mode and see if that works? If not, can you try it on Firefox and a few others to see? 

This would usually be caused by some external application or similar interfering with the events being sent. 


I’ve looked into the possible reasons and couldn’t find a solution unfortunately. I ended up calling the API in our backend server so we wouldn’t get the CORS error anymore.


Reply