FMS Data API vs CORS

Of course whenever we write a JS Widget we need to get data into it.

We can run a script in FM that gathers data with the Execute Data API script step, though I made a previous post about some issues I’ve had with that. @Jeremy Brown proposed, alongside some of my own thinking, that pulling it from the FMS Data API solves the issues I was having. So I’m pursuing/exploring that now and I’ve figured out how to call that with fetch.

But I can’t get it to work without getting CORS errors:

“Origin null is not allowed by Access-Control-Allow-Origin. Status code: 200” is the error I get in production mode — when the code is all in a text field in FM and the web viewer is pointed at that.

Replace “null” with “localhost:1234” or whatever when in dev mode — when the code is hosted by parcel or something similar in VS Code.

According to ChatGPT and a couple of Stack Overflow answers those errors are to be expected when calling the FMS Data API directly from JS in a browser (or web viewer). The answer seems to be “use curl”. But umm.. curl is a command line command (or it’s options in a FM script step) — how do you use curl from within a JS widget in a web viewer? Or if not that, then how else do we access the FM Data API from within a web viewer without these errors?

Anyone had to deal with this and found an answer? Thanks!