Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Make authenticated request to Jira REST API with oauth access token

Hi,

I have installed Jira software server on my computer. It's up and running on localhost:8080. I have an admin account on it.

My goal is to make requests to the api of that server, using node js.

I have followed this tutorial to get an access token that I should be able to use to make an authenticated request to the Jira REST API.

My problem is that I can't figure out the proper way to make API calls with that access token. Should I put it in the headers ? In the query parameters ?

I've worked with other APIs, for which I would do something like :

axios.get(jiraUrl +  '/rest/api/2/myself',
{
{
headers: {
'Authorization': `Bearer ${oauthAccessToken}`,
'Accept': 'application/json'
}
}
)
.then(result => console.log(result)
.catch(error => console.log(error)

 But this doesn't work with jira.

/rest/api/2/myself is supposed to return data about the logged in user, but I get a 401 error saying no user is logged in. What I understand from this is that I didn't provide the authentication token in the right way.

I have searched a lot of community discussions, but didn't manage to find how to properly make that request. Does anyone have a way to do this ?

Thanks.

1 answer

Hello @Axel , I am also running into this issue. have you solved this issue ?

Hi,

I ended up using jira-client.

It allows you to do pretty much everything, here's the full doc : https://jira-node.github.io/class/src/jira.js~JiraApi.html.

So basically, once you've got your accessToken and accessTokenSecret from oauth, you can call the following method to get a JiraCleint object, on which you can call any method from the doc.

function getJiraClient(accessToken, accessTokenSecret) {
  return new JiraClient({
    protocol: process.env.JIRA_PROTOCOL,
    host: process.env.JIRA_HOST,
    port: process.env.JIRA_PORT,
    oauth: {
      consumer_key: process.env.JIRA_CONSUMER_KEY,
      consumer_secret: PRIVATE_KEY,
      access_token: accessToken,
      access_token_secret: accessTokenSecret,
      signature_method: 'RSA-SHA1',
    },
    apiVersion: '2',
    strictSSL: false,
  });
}

 

Hope that helps!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,104 views 8 28
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you