Hi,
I’m new to Forge platform for Atlassian’s cloud products.
I’m just exploring things, and I’m basically trying consume a rest API that has some data on my server.
but Im having an issue with fetch API, I get the error below:
Something went wrong
There was an error invoking the function - XMLHttpRequest is not defined
ReferenceError: XMLHttpRequest is not defined
at dispatchXhrRequest (tab.js:7386:19)
at new Promise (<anonymous>)
at xhrAdapter (tab.js:7367:10)
at dispatchRequest (tab.js:13077:10)
at Axios.request (tab.js:12911:15)
at Axios.<computed> [as get] (tab.js:12932:17)
at Function.wrap [as get] (tab.js:7216:15)
at DataService_DataService.getCurrentWeather (tab.js:13744:28)
at Object.onChange (tab.js:13757:44)
at tab.js:7772:30
my code is this:
import ForgeUI, {
ProjectPage,
useState,
Heading,
Button,
Macro,
render,
Text,
} from "@forge/ui";
import { fetch } from "@forge/api";
const App = async () => {
const result = await api.fetch("https://jsonplaceholder.typicode.com/todos/1");
const status = await result.status;
const [count, setCount] = useState(0);
return (
<ProjectPage>
<Heading size="large"> Here are your key indexes</Heading>
<Text> Please click here {status}</Text>
<Button
text={`Count is ${count}`}
onClick={() => {
setCount(count + 1);
}}
/>
</ProjectPage>
);
};
export const run = render(<Macro app={<App />} />);
and my manifest:
modules:
jira:projectPage:
- key: some-site-jira-poc-page
function: main
title: Some Title
icon: https://www.somesite.com/_nuxt/img/0b10d18.png
function:
- key: main
handler: tab.run
app:
id: ari:cloud:ecosystem::app/some-app-id
permissions:
external:
fetch:
backend:
- '*.typicode.com'
scopes: []
package json (might be useful to pinpoint):
{
"name": "forge-ui-starter",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"scripts": {
"lint": "./node_modules/.bin/eslint src/**/* || npm run --silent hook-errors",
"hook-errors": "echo '\\x1b[31mThe build failed because a Forge UI hook is being used incorrectly. Forge UI hooks follow the same rules as React Hooks but have their own API definitions. See the Forge documentation for details on how to use Forge UI hooks.\n' && exit 1"
},
"devDependencies": {
"eslint": "^6.5.1",
"eslint-plugin-react-hooks": "^2.1.2"
},
"dependencies": {
"@forge/api": "^2.3.0",
"@forge/ui": "^0.13.1"
}
}