How to use environment variables in custom code with fetch (for FormData upload)

Hi all,

In our project, we have a document upload scenario where we must use fetch in custom code because the API expects multipart/form-data and ap.http does not handle FormData correctly.

The challenge is that with fetch we are currently forced to hardcode the API URL.

Is there a way to retrieve environment variables (e.g., MVL_WF_BE_URL) in custom code so we can keep the URLs dynamic, the same way ap.http uses them?

Any guidance or examples would be much appreciated.

— Thanks in advance!

2 Likes

Hi,

You can access environment variables in your custom code using the following syntax:

const apiUrl = window.environments.MVL_WF_BE_URL;

Thanks,

1 Like

@ziyad getting undefined

1 Like