Hello All,
I want to call the third party api using fetch api in forge app. I have also added the api url manifest.yml file
as following:
permissions:
external:
fetch:
backend:
- "https://my-third-party-api-url.com/v2/customer"
Please find my code as below.
//import ForgeUI, { render, ProjectPage, Fragment, Text } from '@forge/ui';
import ForgeUI, { render, ProjectPage, Fragment, Button } from '@forge/ui';
import { fetch } from '@forge/api';
const App = () => {
async function getThirdParyData() {
console.log("QS Custom getThirdParyData() function called.");
//const params2 = new URLSearchParams("page=1&perPage=1");
//https://my-third-party-api-url.com/v2/customer?page=1&perPage=1
const result = await api.fetch(
'https://my-third-party-api-url.com/v2/customer', {
method: 'GET',
headers: {
'api-key': 'sdfgisern123213',
'Accept': 'application/json'
},
qs:{'page':'1','perPage':'2'}
});
let data2 = await result.json();
// console.log('data2 ==', json);
console.log('json result ==', data2);
const status = await result.status;
console.log('Got status2 ==', status);
}
return (
<Fragment>
<Button
text="Get extenal api data"
onClick={async () => {
await getThirdParyData();
}}
/>
</Fragment>
);
};
I am facing challenges to pass query params as ā?page=1&perPage=1ā in the GET method request. Sample request url = āhttps://my-third-party-api-url.com/v2/customer?page=1&perPage=1ā
Please correct if iām missing something. Or else suggest me another library in forge app which could support this option.