How to use the jira rest API to update the issue's sprint

tony picarello August 15, 2017

I am usinf jira 6.4.x and have successfully created an app that uses the jira rest API to create issues, and to update various fields.  I am having issues setting the Sprint though.  It is a custom field, and via the rest/api/2/issue/xxx-nnnn/editmeta, the field has this format:

 "customfield_11004":
 {
  "required":false,
  "schema":
  {
    "type":"array",
    "items":"string",
    "custom":"com.pyxis.greenhopper.jira:gh-sprint",
    "customId":11004
  },
  "name":"Sprint",
  "operations":["set"]
 }

And when I pull the sprint data using a GET, the sprint is defined as:

 "customfield_11004": [
 "com.atlassian.greenhopper.service.sprint.Sprint@20de96ed[rapidViewId=38,state=FUTURE,name=Sprint 19,startDate=<null>,endDate=<null>,completeDate=<null>,sequence=174,id=174]"
 ]

  So... trying to do a PUT to set the sprint, and am lost.  I tried the following:

{
 "update": 
{
    "customfield_11004": [
    {
        "rapidViewId": 38,
         "state": "ACTIVE",
         "name": "Sprint 18",
         "completeDate": null,
         "sequence": 173,
         "id":"173"
       }]
  }
}

But that give me an error:

{
 "errorMessages": [
 "Field with id' customfield_11004' and name 'Sprint' does not support operation 'id' Supported operation(s) are: 'set'"
 ],
 "errors": {}
}

  I tried a "set using the following:

{
 "update": 
 {
  "customfield_11004": [
    {"set" : {"rapidViewId": 38}},
     {"set" : {"state": "ACTIVE"}},
     {"set" : {"name": "Sprint 18"}},
     {"set" : {"completeDate": null}},
     {"set" : {"sequence": 173}},
     {"set" : {"id": 173}}]
 }
}

but I get an internal server error

{
 "errorMessages": [
 "Internal server error"
 ],
 "errors": {}
}

  What I really want to do is set just the id that is 173 in the example above..   Any ideas?  TIA  

1 answer

0 votes
Steven F Behnke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 15, 2017

Instead of using the "update custom field" API, you should instead use the JIRA Software API which allows you to add issues to a sprint via Sprint ID:

https://jira.fqdn.com/rest/agile/1.0/sprint/173/issue

{
  "issues":[
    JRA-1,
    JRA-2500,
    JRA-301556

  ]
}

https://docs.atlassian.com/jira-software/REST/latest/#agile/1.0/sprint-moveIssuesToSprint  

tony picarello August 16, 2017

Thanks for replying.  I appreciate it.

I tried your suggestion... did not work.

I am using PostMan plugin to Chrome... anyway, my json is:

{ "issues": ["xxx-nnnn"]}

I needed the quotes on the issue id.

I used rest address (I did a POST):

/jira/rest/api/2/sprint/173/issue
response:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<status>
<status-code>404</status-code>
<message>null for uri: https://eadget-devtools.external.lmco.com/jira/rest/api/2/sprint/173/issue</message>
</status>

 

I know I have permission to view the sprint, and the sprint is active.  This is crazy :)  It is like the API does not support sprint resource... because if I use address /jira/rest/api/2/yadayada/173/issue, I get the same 404 error.

Steven F Behnke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 16, 2017

Can you provide your jira base url (replace your domain with 'example'), exact input, and exact output from both the endpoints you're trying to use?

tony picarello August 17, 2017

Sure... the base_url is:

https://example.com/jira/rest/api/2/

 

FYI... for creating issues, I can successfully use:

https://example.com/jira/rest/api/2/issue

 

Anyway, using postman for my testing, input is :

- Content-Type is application/json

- "Authorization" is "Basic"

- POST method

- message body contains just the following:

{"issues": ["TLS-2965"]}

- Postman has some options for data input... like raw, x-www-form-uelencoded, binary, form-data... so I am using raw

url:  base_url/sprint/173/issue

 I cannot post header contents of the response... page flags something as inappropriate.

Suggest an answer

Log in or Sign up to answer