Unable to make API calls in Forge App

Hi, When I try to make API calls from within a Forge App the host is resolved to “jira” and an error is thrown. In the browser, the error is:
Refused to connect to ‘https://jira/rest/api/3/issuetype’ because it violates the following Content Security Policy directive: “connect-src ‘self’ https://api.atlassian.com/metal/ingest”.

In the app, my code is:

import api, { route } from "@forge/api";

const getIssueTypes = async () => {
  try {
    console.log("Start");
    const response = await api.asApp().requestJira(route`/rest/api/3/issuetype`, {
      headers: {
        'Accept': 'application/json'
      }
    });
    
    console.log(`Response: ${response.status} ${response.statusText}`);
    console.log(await response.json());
  } catch (error) {
    console.log("Error: ", error);
    throw error;
  }
}

The permissions seem to be fine as I have added the scopes to the manifest.
What am I doing wrong?

Hi @Morgan,

It looks like you are trying to execute this code in the browser in a Custom UI iframe, however, @forge/api is intended for use within Forge functions which execute in the back end, not the browser.

Regards,
Dugald

1 Like