I’m trying to set up basic authentication for Jira using Node.js. The docs mention ‘localhost:8080’ but I’m not sure what URL to use. Some sources say it’s outdated. I’m using axios for requests.
Here’s what I’ve tried:
axios.get('https://mycompany.atlassian.net', {
auth: {
username: 'myuser',
password: 'mypass'
}
}).then(response => {
console.log(response.data);
}).catch(error => {
console.error('Error:', error.message);
});
But it’s not working. I’ve been stuck on this for a couple of days now. Any ideas on how to properly authenticate with the Jira API? Thanks for any help!
I’ve been working with the Jira API quite a bit lately, and I can tell you that authentication can be tricky. One thing that really helped me was switching to using a Personal Access Token (PAT) instead of my password. It’s more secure and less likely to cause issues.
Here’s what worked for me:
Generate a PAT in your Atlassian account settings. Use the PAT instead of your password in the auth object. Make sure you’re using the correct API version in the URL (v2 or v3).
Also, I found that setting up proper error handling was crucial. Sometimes the error messages from Jira can be cryptic, so logging the full error response body can give you more insight into what’s going wrong.
Don’t forget to check your network settings too. I once spent hours debugging only to realize my company’s firewall was blocking the requests!
hey man, i had the same issue last week. turns out you need to use the /rest/api/2/ endpoint. try this:
axios.get('https://mycompany.atlassian.net/rest/api/2/myself', {
auth: {
username: 'your-email',
password: 'your-api-token'
}
})
also, make sure ur using an API token instead of ur actual password. hope this helps!
I’ve encountered similar authentication issues with the Jira API. The key is using the correct endpoint and authentication method. For Jira Cloud, it is advisable to use a Personal Access Token (PAT) rather than a password.
Below is a more robust approach that sets up a reusable axios instance:
const axios = require('axios');
const instance = axios.create({
baseURL: 'https://your-domain.atlassian.net',
headers: {
'Authorization': `Basic ${Buffer.from('your-email:your-PAT').toString('base64')}`,
'Accept': 'application/json'
}
});
instance.get('/rest/api/3/myself')
.then(response => console.log(response.data))
.catch(error => console.error('Error:', error.response.data));
Remember to replace ‘your-domain’, ‘your-email’, and ‘your-PAT’ with your actual details. The PAT can be generated through your Atlassian account settings.