Making API Calls In a Node.js Add-On Application

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.

 

1 answer

Don't you need to provide any sort of authentication?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Apr 22, 2018 in Jira Software

How-to setup a secured Jira Software 7.9.0 on Ubuntu 16.04.4 in less than 30 minutes

...PermissionsStartOnly=true User=www-data Group=www-data ExecStart=/opt/jira/bin/startup.sh ExecStop=/opt/jira/bin/shutdown.sh TimeoutStartSec=120 TimeoutStopSec=600 PrivateTmp=true [Install] WantedBy...

2,073 views 14 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you