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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,551,853
Community Members
 
Community Events
184
Community Groups

Get attachments from API using NODE and getting error 401

I am trying to download the contents of an attachment from a issue with nodejs. But I always get - Unauthorized (401)

But I do with the same user and token several other calls successfully. is I have the same header in the call. see code below:

 

async function baixarArquivoXls2(id) {
  try {
    const headers = {
      'Authorization': `Basic ${Buffer.from(conection.username + ":" + conection.password
        // 'email@example.com:<api_token>'
      ).toString('base64')}`,
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    };
    const response = await axios.get(conection.urlbase+'/secure/attachment/'+id,  { headers });
    console.error('OK');
  } catch (error) {
    console.error('Erro:', error);
  }
}
I Tryed by this way too. But get a 404 bad request
null for uri: <mylink>/rest/api/2/attachment/content/24200'
async function baixarArquivoXls3(id) {
  try {
    const headers = {
      'Authorization': `Basic ${Buffer.from(conection.username + ":" + conection.password
        // 'email@example.com:<api_token>'
      ).toString('base64')}`,
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    };
    const response = await axios.get(conection.urlbase+'/rest/api/2/attachment/content/'+id,  { headers });
    console.error('OK');
  } catch (error) {
    console.error('Erro:', error);
  }
}
Where are my error? anybody knows?

1 answer

0 votes
Ian Carlos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Apr 18, 2023

Try this

Create a Jira Token for your user, this link will explain: Manage API tokens for your Atlassian account (and it will guide you to this link API Tokens)

Save the token

Modify your code to

const headers = {
      'Authorization': 'Token the_token_you_just_created'
      ...
and
await axios.get(conection.urlbase+'/secure/attachment/'+id,  { headers: headers, auth: {username: your_jira_user_email, password: the_token_you_just_created } });

 

Let me know if this worked for you

 

Good luck!

conection.username and conection.password stores exactly these values.

Ian Carlos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Apr 18, 2023

Okay, but, have you tried modifying the code the way I told you? changing the Auhtorization in the header and set the auth like another param

Just in case, test it

 

In Python worked for me applying these changes

Suggest an answer

Log in or Sign up to answer