You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
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"]
}
}
We often have questions from folks using Jira Service Management about the benefits to using Premium. Check out this video to learn how you can unlock even more value in our Premium plan. &nb...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events