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!
Dear @Wilhelm ,
welcome to the community.
I recommend to debug the sent/received data from Power Scripts to Jira. Means, try to output the HTTP request, its HTTP_CODE and JSON response to know more about this.
Then, copy&paste this information into a REST client / REST browser (Postman or cURL) and execute. Compare the response with the one from Power Scripts.
Enable as much debugging as possible.
If you cannot solve it alone, don't hesitate to open a support request at the vendor. But before have a look at their documentation.
So long
Thomas
Thank you! I solved the Issue with a hardcoded string as explained in Working with JSON Data
Best regards
Wilhelm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.