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
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
领英推荐
ATLASSIAN_API_KEY=ADD-YOUR-API-KEY-HERE
LEAD_ACCT_ID=557058:f9bcdb25-24a5-4501-927c-588
DOMAIN=horeaporutiu
PROJECT_KEY=TEST22
PROJECT_NAME=TestProject22
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.