Jira REST API Client
Jira.js is a robust, production-ready JavaScript and TypeScript library designed for seamless interaction with Atlassian Jira Cloud APIs. Currently in version 5.3.1, it provides comprehensive coverage for Jira Cloud REST API v2/v3, Jira Agile Cloud API, and Jira Service Desk Cloud API. The library is actively maintained with regular updates to incorporate new Jira API features and bug fixes, typically releasing patches and minor versions frequently. Its key differentiators include full TypeScript support with exhaustive type definitions, tree-shakability for optimized bundle sizes in browser environments, universal compatibility with Node.js (v20+) and modern browsers, and complete API coverage. It adheres to a modern stack, supporting both ES Modules and CommonJS, and is widely used in production for building Jira integrations, automation tools, webhooks, and custom applications.
Common errors
-
mime.getType is not a function
cause The CommonJS build of jira.js was attempting to use an ESM-only dependency (`mime`) which led to this error in CJS environments.fixUpgrade jira.js to version 5.3.1 or later. This version replaced the problematic `mime` dependency with `mime-types` which supports both ESM and CJS. -
Error: Cannot find module 'jira.js/some-internal-path'
cause Reliance on internal aliases or incorrect module paths, particularly the `~` alias, which was removed due to build system incompatibilities.fixReview your import statements. Ensure you are importing from documented public API paths (e.g., `jira.js` or `jira.js/auth`) and not relying on internal aliases that are subject to change or removal. -
Jira API Response Error: 400 ... 'projectId' must be specified multiple times
cause When calling `getWorkflowSchemeProjectAssociations`, multiple project IDs were being serialized as a single comma-separated query parameter instead of multiple `projectId=` parameters, which Jira's API did not correctly parse.fixUpgrade jira.js to version 5.3.0 or later. This version fixed the serialization logic for multiple project IDs in `getWorkflowSchemeProjectAssociations`. -
TypeError: client.version2.issues.bulkFetchIssues is not a function
cause Incorrect URL generation for the `bulkFetchIssues` method within the `Version2Client`.fixUpgrade jira.js to version 5.2.2 or later to ensure the correct URL is generated for `version2.issues.bulkFetchIssues`.
Warnings
- breaking Version 5.0.0 introduced full ESM (ECMAScript Modules) support and removed all telemetry-related code. This means that direct `require()` statements might behave differently or fail for certain module paths compared to prior versions if not correctly configured for hybrid ESM/CJS environments.
- breaking The minimum required Node.js version has been updated to Node.js 20 or newer. Running jira.js on older Node.js versions will result in compatibility errors.
- deprecated Several issue search methods have been deprecated in favor of enhanced alternatives: `IssueSearch.searchForIssuesUsingJql`, `IssueSearch.searchForIssuesUsingJqlPost`, and `IssueSearch.searchForIssuesIds`.
- gotcha The `~` alias, previously used for certain internal paths, was removed due to compatibility issues with various build systems. Projects relying on this alias for direct imports would have failed.
- gotcha Past versions (prior to v5.3.1 and v5.1.1) experienced issues with the CommonJS build, including `mime.getType is not a function` errors and general `CommonJS requiring` problems, impacting projects that explicitly used the CJS distribution.
Install
-
npm install jira.js -
yarn add jira.js -
pnpm add jira.js
Imports
- Version3Client
const { Version3Client } = require('jira.js');import { Version3Client } from 'jira.js'; - BasicAuth
import { BasicAuth } from 'jira.js';import { BasicAuth } from 'jira.js/auth'; - Issue
import { Issue } from 'jira.js';import { Issue } from 'jira.js/api';
Quickstart
import { Version3Client } from 'jira.js';
import { BasicAuth } from 'jira.js/auth';
const host = process.env.JIRA_HOST ?? 'https://your-domain.atlassian.net';
const email = process.env.JIRA_EMAIL ?? 'your-email@example.com';
const apiToken = process.env.JIRA_API_TOKEN ?? 'YOUR_JIRA_API_TOKEN';
const client = new Version3Client({
host,
authentication: new BasicAuth({ email, apiToken }),
});
async function createJiraIssue() {
try {
const issue = await client.issues.createIssue({
fields: {
project: {
key: 'YOURPROJECTKEY', // e.g., 'TEST'
},
summary: 'Example issue created by jira.js client',
issuetype: {
name: 'Task', // Or 'Bug', 'Story' etc.
},
description: {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'This is a test issue created programmatically using jira.js.',
},
],
},
],
},
priority: {
name: 'Medium',
},
},
});
console.log(`Issue created successfully: ${issue.key} at ${host}/browse/${issue.key}`);
return issue;
} catch (error) {
console.error('Error creating Jira issue:', error);
if (error.response) {
console.error('Jira API Response Error:', error.response.status, error.response.data);
}
throw error;
}
}
// To run this example, ensure JIRA_HOST, JIRA_EMAIL, and JIRA_API_TOKEN are set
// in your environment variables or replace the placeholders directly.
// createJiraIssue();