I'm making my first Node.js Add-On for Jira using the Atlassian-Connect Express framework and I'm having trouble making API calls.
In prior Add-Ons I used a basic JavaScript/PHP/Apache setup in order to create a connection between my own application and my JIRA instance using basic authorization (no JWT tokens). Making an API call was as simple as using AP.require.
I'm not entirely sure how to make API calls using ACE because when I use AP.require I receive a 403 error for simple GET requests. Should I be using Node to make API calls rather than AP.require? And where in ACE would I do this? I'm not sure if I have to create a route for making API calls or if I have to create a function in the Express build in app.js.
Originally I had my API calls setup in its own .js file as the following:
const baseUrl = "myinstance.atlassian.net";
function getAllProjects() {
return get(baseUrl + '/rest/api/2/project');
}
function get(url) {
return fetch(baseUrl + url).then(onSuccess, onError);
}
function onSuccess(response) {
return response.json();
}
function onError(error) {
console.log(error); // eslint-disable-line no-console
}
When I try this I am unable to make a call to the API because it attaches my ngrok host link to the URL request like so:
ngrock_address/myinstance.atlassian.net/rest/api/2/project.
So I changed the code to the following:
const baseUrl = "myinstance.atlassian.net";
const token = document.getElementById("jwt-token").content;
function getAllProjects() {
return get(baseUrl + '/rest/api/2/project');
}
function get(url) {
AP.require('request', function(request) {
request({
url: url,
headers: {
'Authorization': `JWT ${token}`,
},
success: function(response) {
response = JSON.parse(response);
console.log(response);
},
error: function() {
console.log(arguments);
}
});
});
}
function onSuccess(response) {
return response.json();
}
function onError(error) {
console.log(error); // eslint-disable-line no-console
}
But this only yields a 403 forbidden response.
Don't you need to provide any sort of authentication?
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.