Hey together,
I´m new to Jira and Power Scripts and trying to solve a task with the REST API of Jira.
The task I would like to solve is the following: an issue should execute a sil-script via a checkbox (customfield) on saving via an eventlistener with which the issue creates this issue as a "work package" via the rest-api in another jira instance.
So I have two jira instances and I want to transfer a specifically issue as a work package from one to the other.
For testing with the REST API I tried httpGet and with the following code I´m getting a response of the server:
struct fields{
string description;
}
struct issueInfo{
string expand;
string id;
string key;
fields fie;
}
// Create request
HttpRequest request;
//HttpHeader authHeader = httpBasicAuthHeader("admin", "1234");
HttpHeader authHeader = httpBasicAuthHeader("admin", "1234");
request.headers += authHeader;
// Post data and get response
issueInfo issueInfo = httpGet("https://.../rest/api/2/issue/TESTPROJ-7", request);
runnerLog(issueInfo.expand);
runnerLog(issueInfo.id);
runnerLog(issueInfo.key);
runnerLog(issueInfo.fie.description);
But my httpPost code gets no response and I don´t know why, maybe the structs are incorrect? My code is as follows:
struct project {
string key;
}
struct issuetype{
string name;
}
struct customfield{
string key;
}
struct fields{
project project;
string summary;
string description;
issuetype issuetype;
customfield customfield_10205;
}
struct issue{
fields fields;
}
struct returnData{
string id;
string key;
string self;
}
// Create request
HttpRequest request;
//HttpHeader authHeader = httpBasicAuthHeader("admin", "1234");
HttpHeader authHeader = httpBasicAuthHeader("admin", "1234");
request.headers += authHeader;
HttpHeader header = httpCreateHeader("Content-Type", "application/json");
request.headers += header;
issue issuefields;
// Set fields
issuefields.fields.project.key = "TESTPROJ";
issuefields.fields.summary = "New Issue created with Rest API";
issuefields.fields.description = "Testing with Rest API";
issuefields.fields.issuetype.name = "Work Package";
issuefields.fields.customfield_10205.key = "TESTPROJ-13";
// Check for correct format of JSON
runnerLog(toJson(issuefields));
// Post data and get response
returnData result = httpPost("https://.../rest/api/2/issue/", request, issuefields);
runnerLog(result);The problem I´m facing is: I already tried many ways to solve this. I have build the needed JSON with structs and the output seems to be correct but I still get no response.
I already created the customfield (checkbox) and I know how to set the EventListener for it, my only Problem is to create the Issue in the other Jira Instance.
I hope someone can help me and sorry if my code is not the best, I´m still a beginner.
Thank you in advance!