Forums

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

Create incident in Jira using 3rd party tool

vivek gupta
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 5, 2020

Hi All 

I am trying to "Create issue in Jira " using groovy code.I am using "Basic Auth " using REST API : https://xxxxxxxxxxx.atlassian.net/rest/api/3/issue/ 

Same works when i run from postman .

But it is failing when I execute using java/groovy code .I am getting error : Any idea why it may be failing ? Also Is basic auth supported when invoked from Java code ?

Json FOR CREATING REQ->{ "fields" : { "project" : { "key" : "ITTSD" } , "summary" : "vivekgupta" , "description" : { "type" : "doc" , "version" : 1 , "content" : [ { "type" : "paragraph" , "content" : [ { "text" : "igniouser for customer" , "type" : "text" } ] } ] } , "issuetype" : { "name" : "Incident" } } }

Basic authentication
Inside request
{ "fields" : { "project" : { "key" : "ITTSD" } , "summary" : "test" , "description" : { "type" : "incident" , "version" : "1" , "content" : [ { "type" : "paragraph" , "content" : [ { "text" : "igniouser for test" , "type" : "text" } ] } ] } , "issuetype" : { "name" : "Incident" } } }

 

Inside post response failure
Statuscode 400
Statusline HTTP/1.1 400
Line 79->[errorMessages:[], errors:[summary:Field 'summary' cannot be set. It is not on the appropriate screen, or unknown., description:

Field 'description' cannot be set. It is not on the appropriate screen, or unknown.]]
Result: [1, Error in creating the Ticket]

 

Code is as follows : 

def headermap=[:];
StringBuilder sbf = new StringBuilder("");
sbf.append('{ "fields" : { "project" : { "key" : "ITTSD" } , ')
sbf.append('"summary" : "vivekgupta" , ')
sbf.append('"description" : { ')
sbf.append('"type" : "doc" , ')
sbf.append('"version" : 1 , ')
sbf.append('"content" : [ { ')
sbf.append('"type" : "paragraph" , ')
sbf.append('"content" : [ { ')
sbf.append('"text" : "igniouser for customer" , ')
sbf.append('"type" : "text" } ] } ] } , ')
sbf.append('"issuetype" : { ')
sbf.append('"name" : "Incident" } } }')


String bodyJson=sbf.toString();
println "Json FOR CREATING REQ->"+bodyJson;
httpRequester = new groovyx.net.http.HTTPBuilder('https://customer.atlassian.net/rest/api/3/issue/');
//println APIAuthRequired
httpRequester.ignoreSSLIssues()
//println "setheaders"
//httpRequester.setHeaders(headermap)
def AuthType = "basic"
if("true".toString().toLowerCase() == "true")
{
//headermap.put("Authorization",authorizationString)
httpRequester.setHeaders(headermap)
//println("Inside Basic Authentication");
switch(AuthType)
{
case "basic" :
println "Basic authentication"
httpRequester.auth.basic("userid","password")
break;
default :break;
}
}

 

httpRequester.request(groovyx.net.http.Method.POST) { req ->

println "Inside request"
httpRequester.ignoreSSLIssues()
requestContentType = groovyx.net.http.ContentType.JSON
body = "{ \"fields\" : { \"project\" : { \"key\" : \"ITTSD\" } , \"summary\" : \"test\" , \"description\" : { \"type\" : \"incident\" , \"version\" : \"1\" , \"content\" : [ { \"type\" : \"paragraph\" , \"content\" : [ { \"text\" : \"igniouser for test\" , \"type\" : \"text\" } ] } ] } , \"issuetype\" : { \"name\" : \"Incident\" } } }"
println body
response.success = { resp,json ->
println "Inside post response success"
httpResponse = resp
println "Statuscode"+resp.statusLine.statusCode
println "Statusline"+resp.statusLine
jsonResponse = json
}

response.failure = { resp,json ->
println "Inside post response failure"
httpResponse = resp
println "Statuscode "+resp.statusLine.statusCode
println "Statusline "+resp.statusLine
jsonResponse = json
println "Line 79->"+jsonResponse
return["1","Error in creating the Ticket"]
}
}

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events