Setting up authentication with node-jira library

I’m trying to integrate my app with JIRA’s API using the node-jira package. Everything seems to be configured correctly but I keep getting authentication errors when making requests.

Here’s my current setup:

var JiraClient = require('jira').JiraApi;

var client = new JiraClient('https', 'my-company.atlassian.net', 443, 'myusername', 'mypassword', '2');

client.getCurrentUser(function(err, user) {
  if(err){
    console.log('Error:', err);
    return;
  }
  console.log('User data retrieved successfully');
});

The error I’m getting is:

401: Error while getting current user

I’ve double-checked my credentials and they work fine when logging into JIRA through the web interface. Has anyone encountered similar authentication issues with this library? What might be causing the 401 error?

yep, ur correct! Atlassian switched things up. now u gotta use API tokens instead of passwords. just get one from your acc settings and sub it in for the password. good luck with it!

This happens frequently with Atlassian Cloud. They removed support for basic authentication using regular passwords due to security concerns. To resolve your issue, you need to generate an API token from your account settings and replace your password with this token in the integration. Additionally, ensure you are using your email address as the username instead of just your Jira username. I encountered a similar issue during an integration update, and switching to the API token resolved it immediately. You can create an API token under Account Settings > Security > API tokens.

Had the exact same problem last month migrating our ticketing system. It’s definitely auth-related, but there’s another gotcha beyond the API token. Check you’re using the right constructor parameters for your node-jira library version. Some versions want the config object format instead of individual parameters. Try restructuring your client initialization: new JiraClient({protocol: 'https', host: 'my-company.atlassian.net', port: 443, username: '[email protected]', password: 'your-api-token', apiVersion: '2'}). Also double-check your Atlassian instance URL is exact - subdomain differences can cause auth failures even with correct tokens.