Solved

[Dashboard REST API] How can we query the endpoints in the frontend?


Userlevel 1
Badge
  • Conversationalist
  • 6 replies

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?

icon

Best answer by gsw1 5 May 2022, 06:57

View original

4 replies

Userlevel 7
Badge +10

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.

Userlevel 1
Badge

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).

Userlevel 6
Badge +8

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. 

Userlevel 1
Badge

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