Hi there!,
I’m trying to make MS Graph API calls from my forge app and I can’t. I tried this using the fetch API but this doesn’t work and I don’t receive any error. Could someone please help me with this?
This is my code:
async function getGraphAuthToken() {
const requestUrl = 'https://login.microsoftonline.com/MY TENANT ID/oauth2/v2.0/token';
var details = {
'grant_type': 'client_credentials',
'client_id': 'MY CLIENT ID',
'client_secret': 'MY CLIENT SECRET',
'scope': 'https://graph.microsoft.com/.default'
};
var formBody = [];
for (var property in details) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(details[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
var formBodyString = formBody.join("&");
try {
console.log('before');
const response = await fetch(requestUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
'Accept': '*/*'
},
body: formBodyString
});
console.log('after');
const data = await response.json();
console.log(data);
// Now you can use the new access token
return data.access_token;
} catch (error) {
console.error('Error:', error);
}
}
And in the console i only see the “before” message but when the workflow crashes it doesn’t show any error message.
This is my manifest file:
permissions:
scopes:
- read:jira-user
- read:jira-work
- write:jira-work
- read:user:jira
- read:group:jira
- read:project-role:jira
- read:project:jira
- write:project-role:jira
- read:avatar:jira
- read:project-category:jira
- write:group:jira
external:
fetch:
backend:
- 'https://login.microsoftonline.com'
- 'https://graph.microsoft.com'
modules:
trigger:
- key: user-manager-app
function: main
events:
- avi:jira:created:issue
function:
- key: main
handler: index.run
Thank you all for your time.
Best regards.