[Solved] Project won't GET data from API in Web Preview [CORS issue]

i found a way to get around “cannot GET” errors in webapi (due to CORS - cross origin issue). the answer is allOrigins whose catch phrase is " Pull contents from any page via API (as JSON/P or raw) and avoid Same-origin policy problems."

the original problem started because of this behavior:

the link below works in a browser and also works in Postman but does NOT work in Thunkable (due to CORS issues apparently)

http://numbersapi.com/2000/year?json

this is the result from a browser:

but when coded in thunkable, it returns with a response “cannot GET”.

Error
Cannot GET /web-build/numbersapi.com/2000/year

however if you use allOrigins, you code the url like this:

https://api.allorigins.win/get?url=http://numbersapi.com/2000/year?json

Below is what it looks like when it is entered from a browser. note how the desired url is included in the call. also note that the response of the desired url is now contained as a json variable called contents.

this is how to code it in thunkable. (notice the nested json processing)>

with this result (each successive call gives a different result for the same year)

here’s the project link
https://x.thunkable.com/copy/377e3ddfcfb3e3ae9ba9ce18033d1aca

2 Likes