JavaScript JIRA API for node.js

Installation

Install with the node package manager npm:

$ npm install jira-client        

Examples

Create the JIRA client

// With ES5
var JiraApi = require('jira-client');

// With ES6
import JiraApi from 'jira-client';

// Initialize
var jira = new JiraApi({
  protocol: 'https',
  host: 'jira.somehost.com',
  username: 'username',
  password: 'password',
  apiVersion: '2',
  strictSSL: true
});        

Find the status of an issue

// ES5
// We are using an ES5 Polyfill for Promise support. Please note that if you don't explicitly
// apply a catch exceptions will get swallowed. Read up on ES6 Promises for further details.
jira.findIssue(issueNumber)
  .then(function(issue) {
    console.log('Status: ' + issue.fields.status.name);
  })
  .catch(function(err) {
    console.error(err);
  });

// ES6
jira.findIssue(issueNumber)
  .then(issue => {
    console.log(`Status: ${issue.fields.status.name}`);
  })
  .catch(err => {
    console.error(err);
  });

// ES7
async function logIssueName() {
  try {
    const issue = await jira.findIssue(issueNumber);
    console.log(`Status: ${issue.fields.status.name}`);
  } catch (err) {
    console.error(err);
  }
}
        

JIRA CLOUD REST API TUTORIAL

Steps

  1. Clone the Repo
  2. Install dependencies
  3. Add Env Variables
  4. Run the App

Step 1. Clone the Repo

Git clone this repo onto your computer in the destination of your choice:

git clone https://github.com/horeaporutiu/JIRA-Cloud-REST-API-Tutorial.git
        

then cd into the jira-cloud-tutorial folder:

cd JIRA-Cloud-REST-API-Tutorial
        

Step 2. Install Dependencies

Run npm install to install dependencies. Make sure to have Node.js installed!

Step 3. Add Env Variables

Rename your .sample.env to .env and fill out the necessary env variables! See below for details

Filling out .env

[email protected]

  • This should just be your email, at least it was for me

ATLASSIAN_API_KEY=ADD-YOUR-API-KEY-HERE

  • Click on your account icon in top-right corner -> Manage account -> Security -> Create and manage API token under API token. From there click on Create API token and add it here.

LEAD_ACCT_ID=557058:f9bcdb25-24a5-4501-927c-588

  • First, run the get-users.js file to see your account id. The resulting JSON should give you your ID. This is needed to assign the project to a user.

DOMAIN=horeaporutiu

  • This will be the https://<your-domain>.atlassian.net your-domain part of the URL. For example my URL is https://horeaporutiu.atlassian.net/ so my domain is horeaporutiu

PROJECT_KEY=TEST22

  • This can be anything

PROJECT_NAME=TestProject22

  • This can be anything.

Save the file and run source .env or another command to execute the newest contents of the .env file.

Step 4. Run The App

Run node app.js to try it out! Check out the logs for results. See troubleshooting section below for help.

Have fun! Feel free to alter app.js for it to make sense for you. Check out all of the other files to see the details of the REST API calls!

Troubleshooting

If you run node app.js and get the following error:

error: 
{
  projectName: 'A project with that name already exists.',
  projectKey: "Project 'TestProject223' uses this project key."
}
        

Make sure you change your env variable for PROJECT_NAME and then run source .env or another command to make execute the newest contents of the .env file.



要查看或添加评论,请登录

S Dilli Babu的更多文章

  • Travel and Hospitality Project

    Travel and Hospitality Project

    Step-by-Step Jira Administration Process: 1. Setting Up Issue Types You will need to set up or configure the following…

  • Jira ScriptRunner

    Jira ScriptRunner

    Jira ScriptRunner is a powerful add-on for Jira, developed by Adaptavist, that enhances Jira's automation capabilities…

  • Confluence

    Confluence

    Confluence is a collaboration software developed by Atlassian, designed to help teams organize, share, and collaborate…

  • Jira Admin

    Jira Admin

    Here's a basic overview: 1. User Management: As a Jira administrator, you'll manage user accounts.

  • Rest API in Jira

    Rest API in Jira

    Certainly! Jira's REST API allows you to interact with Jira programmatically, including creating, updating, and…

社区洞察

其他会员也浏览了