Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Create incident in Jira using 3rd party tool

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
Community showcase
Published in Jira Service Management

Why upgrade to Jira Service Management Premium?

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...

235 views 1 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you