Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can i import issues in my instance with Curl?

achraf pato August 27, 2019

My input is a csv file full with issues, i want to import them to my instance, without a manual task 

1 answer

0 votes
DPKJ
Community Champion
August 27, 2019

This has two parts,

One, Jira provide wonderful CSV import functionality in admin section, you can use that, it will prevent you from lots of hassle.

Two, if you want to import it via script/terminal rather then using just curl use any scripting language, like node, python etc.

Here is node sample that I used few months back to create some test data.

CSV structure was,

projectkey,issuetypeid,summary

And node file was like this,

// This code sample uses the 'request' library:
// https://www.npmjs.com/package/request
var request = require("request");
//file stream
var fs = require("fs");
//csv parser
var parse = require("csv-parse");

var fileName = "data.csv"; //name of csv file
var csvData = [];

fs.createReadStream(fileName)
.pipe(parse({ delimiter: ":" }))
.on("data", function(csvrow) {
//console.log(csvrow);
//do something with csvrow
csvData.push(csvrow);
})
.on("end", function() {
//do something wiht csvData
//console.log(csvData);
});

csvData.forEach(function(data) {
var bodyData = `{
"update": {},
"fields": {
"summary":"${data.summary}",
"issuetype":{
"id": "${data.issuetypeid}"
},
"project": {
"key": "${data.projectkey}"
}
}
}`;
console.log(data);
console.log(bodyData)

var options = {
method: "POST",
url: "<JIRA_BASE_URL>/rest/api/2/issue",
headers: {
Authorization: 'Bearer <BASE64_TOKEN>'
Accept: "application/json",
"Content-Type": "application/json"
},
body: bodyData
};

request(options, function(error, response, body) {
if (error) throw new Error(error);
console.log(
"Response: " + response.statusCode + " " + response.statusMessage
);
console.log(body);
});
});

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events