I have a Jira Cloud Forge app that must fetch data from one of my company’s API (External to Jira App).
This is my project structure and source code:
`manifest.yml :
``
Modules:
jira:issueGlance:
- key: ig-support-case
name: CX Support
title: BILL Salesforce
label: Linked Cases
resource: casedetailsViewglance
render: native
resolver:
function: resolver
resources:
key: casedetailsViewglance
path: src/frontend/viewGlance.jsx
scopes:
- write:jira-work
- storage:app
- read:jira-work
- read:jira-user
external:
fetch:
backend:
- “*.cloudhub.io”
**`src/frontend/viewGlance.jsx` **:
const response = invoke(‘sendCommentToSalesforce’, {
casedata: casedata,
comment: comment,
appconfigdata: appconfigdata
});
response.then((sendCommentToSalesforceResponse) => {
if (sendCommentToSalesforceResponse.status === ‘success’) {
addCommentToIssue(comment, sendCommentToSalesforceResponse.currentUser);
} else {
alert("error in sendCommentToSalesforceResponse");
}
})
} catch (error) {
console.error('Error saving config:', error);
}
**`src/resolvers/index.js`** :
resolver.define(‘sendCommentToSalesforce’, async (req) => {
const { casedata, comment, appconfigdata } = req.payload;
const casecommentResponse = await fetch(appconfigdata.apiEndpoint + DEFAULT_COMMENT_API_PATH,
{
method: “POST”,
body: JSON.stringify(apiRequest),
headers: {
“client_id”: appconfigdata.apiClientId,
“client_secret”: appconfigdata.apiClientSecret,
“Content-Type”: “application/json”
}
}).then((data)=>{
console.log(‘Comment response’, data);
return { status: ‘success’}
}).catch((err)=>{
console.log(“Comment response err”, err);
return { status: ‘failed’}
});
});
Finally, the issue:
1- We are able to call external api here, but not able to attached the header part in request and thats the reason we are getting the 401(unAuthorised) in response . So can someone please help me to know how can we add the header values here in request.