Question
How can a JavaScript fetch() action in BetterForms retrieve the URL for a FileMaker container field through the Data API/OttoFMS endpoint, and why was the response unauthorized?
Answer
The request was not being blocked by BetterForms or Klai due to CORS. FileMaker Server’s container streaming setting must be enabled for the generated container URL to work. After enabling streaming, the returned URL opened successfully.
Original Slack Thread
User U06LGNXENSY: I need to know if it is possible to use a javascript function in an action to fetch() a payload. I am currently getting a CORS error and believe that the call is getting blocked by Klai. Any help is very much appreciated.
User UBBJX2EHM: no, if you are fetching from the browser to some 3rd party, it is not Klai that is blocking.
User UBBJX2EHM: the source could ahve cors enabled
User U06LGNXENSY: <@UBBJX2EHM> If I should be able to do this, do you have an example of the code?
User UBBJX2EHM: What exactly is it you want to do. You haven't said?
User U06LGNXENSY: <@UBBJX2EHM> The short of it is, I am trying to get the url for a container field that is generated using the data api. I scoured BF docs and only found 1 article from 2020 that didn't end up having a successful result. I am trying to call an OttoFMS endpoint. I have been successful using Postman, just not with javascript fetch in BetterForms.
User UBBJX2EHM: klai Academy has info,
User UBBJX2EHM: <https://delfsengineering.notion.site/Displaying-FileMaker-Container-Images-and-Documents-352ed1f2a6d6479abc57998652205953?pvs=74|delfsengineering.notion.site/Displaying-F…?pvs=74>
User U06LGNXENSY: Exactly what I was looking for! Many thanks!!
User U06LGNXENSY: <@UBBJX2EHM> For the record, using this example, I still get the "Unauthorized" result just as I have with different methods to obtain the container URL. I think it might be related to security updates in FMS. I would be curious if your devs can still get this example to work.
User UBBJX2EHM: did you change the streaming settings?
User U06LGNXENSY: hmmm, not with this test, but prior, yes. The url generated looks identical to what I have with other methods. But for the sake of trying everything, I will try enabling that setting again.
User UBBJX2EHM: cant work without it
User U06LGNXENSY: Understood, just saying it didn't work before either
User UBBJX2EHM: and have you also inspected the URL you are getting back from FMS?
User UBBJX2EHM: take from the result of the dataapi execute and try to open
User UBBJX2EHM: isolate issue
User U06LGNXENSY: yes, the raw url gives me the unauthorized result
User UBBJX2EHM: ok so did you look at the domain, is it your fms and not local host?
User UBBJX2EHM: post example
User U06LGNXENSY: :face_with_peeking_eye: It worked after changing the streaming setting. Thanks for the assist!
User UBBJX2EHM: uh huh …