Cannot use fetch in mobile application

Hey there! I'm having an issue with using the fetch method in my mobile application. It's working fine in the web app, but in the mobile app, I'm getting an error saying "ReferenceError: fetch is undefined." I'm using the fetch method to skip retool's REST resource query and send the request directly from the mobile device.

Here's an example of my code in the "Query."

function sendJsonToEndpoint() {
  const json = {"key": "value"};
  const url = "http://a.com";
  
  return fetch(url, {
    method: "POST",
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify(json)
  })
  .then(response => response.json())
  .catch(error => console.error('Error:', error));
}

sendJsonToEndpoint();

I am looking forward to your response. I appreciate any help you can provide.

Hello @owais!

Unfortunately Retool mobile does not support third party libraries such as fetch for making requests (while the web app does to an extent).

Is there a reason you aren't using Retool's REST API resource to make the requests? As that is the recommended and preferred method for such actions on mobile.

You should be able to stringify JSON and then POST it to a given URL with the existing tools in Retool's REST API.

Here are some docs on working with mobile requests, let me know if you have any other specific needs for the method or questions!

Thank you for the confirmation about functionality. For now, we have found the solution by allowing IPs .

1 Like