Using node-fetch within my js block

const response = await fetch('https://api.bland.ai/v1/batches', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${apiKey}`,
        'accept': '*/*'
      },
      body: JSON.stringify(payload)
    });

Not sure why I'm getting the error

"fetch is not defined"

I've added the "node-fetch" library to the workflow.

Preload custom JavaScript code and libraries

More context:

This is within a workflow in a code block.

Hey @Zoey_Lee - welcome to the community! I want to jump in and clarify something very quickly - while it's true that Retool executes user JS in a sandboxed environment, we do still allow you to write raw fetch requests.

I typically recommend using the node-fetch-native library, as it is not an ESM-only module. This means it supports require syntax instead of just import.

Let me know if you have any questions!