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

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 vote
Steven Behnke Community Champion Aug 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  

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 Behnke Community Champion Aug 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?

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,233 views 14 19
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot