Hey guys, i want to create a issue on remote jira with jira rest api. Codes in below, it's working great. But i want to return json values, because when the issue created, json returns with issue id. I need this id.
values:
{"id":"117216","key":"TEKFENEHM-1672","self":""}
How can i get id. Can you help me please. Best regards.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.ComponentManager
import groovy.json.StreamingJsonBuilder
def baseURL = "full_url/rest/api/2/issue/";
def authString = "username:password".getBytes().encodeBase64().toString();
def body_req = [
"fields": [
"project":
[
"key": "TEKFENEHM"
],
"summary": "REST API TEST example",
"issuetype": [
"name": "Question"
]
]
]
URL url = new URL(baseURL);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
connection.setRequestProperty( "Authorization", "Basic ${authString}" );
connection.requestMethod = "POST";
connection.doOutput = true;
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }
connection.connect();
Hey man, yes i found the solution.
I used the getInputStream method.
Here is the some documantations about this method.
https://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html#getInputStream()
and here is the my codes.
InputStream response = connection.getInputStream();
String response_string =response.getText()
def jsonSlurper = new JsonSlurper()
def json_object = jsonSlurper.parseText(response_string)
assert json_object instanceof Map
return json_object.id
If you have a problem please notify me. Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI
I want to create an issue from Jira and get the issue details through the API. I need to receive the issue details, So that I can work with my third party app. Hope you can Understand my scenario. Please revert back if you have any solutions.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.