Forge Fetch to External Url fails without tunneling

I’m trying to use the Microsoft Graph API, so endpoints such as
https://graph.microsoft.com/beta/teamwork/devices/${teamworkDeviceId}/activity
https://graph.microsoft.com/beta/teamwork/devices/${teamworkDeviceId}/configuration
https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/${deviceId}/deviceCompliancePolicyStates

When I tunnel the forge app works fine, it’s able to reach the URL via fetch, but without tunneling it returns this error:

error: TypeError: fetch failed

with this fetch:

try {
        const response = await fetch(url, {
            method: 'POST',
            headers: headers,
            body: JSON.stringify(body)
        });
        console.log("response: " + JSON.stringify(response));
        if (response.ok) {
            return await response.json();
        } else {
            console.error(`Received an HTTP/${response.status} ${response.statusText} \t ${await response.text()}`);
            return false;
        }
  } catch (error) {
    console.log("error: " + error);
    return false;
  }

Note that it immediately exists the try and is caught once the fetch is executed. It never prints “response: …”

This is what I have in my manifest.yml, also tried it without the wildcard

permissions:
  scopes:
    - import:import-configuration:cmdb
    - storage:app
  external:
    fetch:
      backend:
        - 'api.atlassian.com'
        - 'https://login.microsoftonline.com/*'
        - 'https://graph.microsoft.com/*'

Hi, can you confirm whether you’re using fetch from @forge/api instead of node-fetch?

2 Likes