Fix
Short answer: The Run JavaScript code action runs on the server, where browser APIs such as fetch() and File don't exist. Make the call with the HTTP connector, or with kf.api() from the Kissflow SDK.
Why it happens
- The Run script connector runs your code as an isolated script on the server, not in a browser.
- Browser objects such as
fetch,Fileandwindowaren't available there.fetch()works only in client-side code, such as page components and form events. - The script also can't read Kissflow system variables such as
kf.account._idorkf.context. Pass any value you need in as an input, or callkf.getContext(), which returns the account and app IDs.
How to fix it
To call an external API:
- Add a HTTP connector action, such as Make an HTTP call (POST) or Make an HTTP call (Custom), for the request.
- If the body needs shaping, add a Run JavaScript code step before it that builds the payload and returns it as an object.
- Map the script's output into the HTTP action's body.
- To process the response, add another Run JavaScript code step after the HTTP action and map the response into it.
To call an API from inside the script:
- Use
kf.api(url, config)from the Kissflow SDK. It works for Kissflow APIs and external APIs. - For Kissflow APIs, use the absolute URL, such as
https://<subdomain>.kissflow.com/user/2/<account_id>, and pass the access key headers.
To check whether a URL is reachable, call it with the HTTP connector and act on the response.
Important
Calls made with
kf.api() time out after 10 seconds. Use the HTTP connector for slow endpoints.