How to log work then resolve issue using rest api?

Pavel Tsydzik February 19, 2013

Hi all.

I try to resolve issue using transition in rest api. So, i send POST request to URL

/rest/api/latest/issue/JMA-105/transitions?expand=transitions.fields&transitionId=5

with POST data:

{
"transition":{"id":"5"},
"\"update\"":{
    "comment":[
        {"add":{"body":"same comment"}}
    ]
},
"fields":{
    "assignee":{"name":"-1"},
    "resolution":{"self":"https://guffer4.atlassian.net/rest/api/latest/resolution/1","name":"Fixed","id":"1"},
    "worklog":{"timeSpent":"10m"}
}
}

And server return responce with code 400 {"errorMessages":[],"errors":{"worklog":"Field does not support update 'worklog'"}}.

if i dont send in POST data fields.worklog issue resolved correctly, bat comment not added.

What structure of the POST data is correct if i need add comment and log work?

thanks in advance.

PS: sorry for my english.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 25, 2013

To update worklog while transitioning issue you have to pass worklog item in "update" section, like you do with comment:

{
  "update": { 
    "worklog" : [ 
      { 
        "add": { 
          "timeSpent" : "6m" 
        } 
      } 
    ] 
  },
  "transition" : { 
    "id" : "4"
  } 
}

Cheers,
Alek.

Pavel Tsydzik March 25, 2013

thanks Alek. its work. I use it in my app for jira free and paid versions

vassilevsky October 5, 2015

Saved my day :D

0 votes
Fahd
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 20, 2013

Hi Pavel,

Please check whether the field worklog is available to be updated during that transition. You can request using /rest/api/2/issue/{issueIdOrKey}/transitions?expand=transitions.fields to check the list of fields that are available.

If worklog field is not in the list, try to add worklog field in the trasition's screen in JIRA UI. Once added, check the list again.

From the documentation here:

" If a field is not configured to appear on the transition screen, then it will not be in the transition metadata, and a field validation error will occur if it is submitted."

Checking the list of available response for code 400, it does match your current problem now which due to the field is not available.

Hope this helps.

Regards,

Fahd

Pavel Tsydzik February 20, 2013

Hi Fahd,

for geting fields for transition i use url /rest/api/2/issue/{issueIdOrKey}/transitions?expand=transitions.fields&transitionId=5 and create form dinamicly based on response. This response is:

{"expand":"transitions","transitions":[{"id":"5","name":"Resolve Issue","to":{"self":"https://guffer4.atlassian.net/rest/api/2/status/5","description":"A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.","iconUrl":"https://guffer4.atlassian.net/images/icons/status_resolved.gif","name":"Resolved","id":"5"},"fields":{"assignee":{"required":false,"schema":{"type":"user","system":"assignee"},"name":"Assignee","autoCompleteUrl":"https://guffer4.atlassian.net/rest/api/latest/user/assignable/search?issueKey=JMA-105&username=","operations":["set"]},"fixVersions":{"required":false,"schema":{"type":"array","items":"version","system":"fixVersions"},"name":"Fix Version/s","operations":["set","add","remove"],"allowedValues":[]},"resolution":{"required":true,"schema":{"type":"resolution","system":"resolution"},"name":"Resolution","operations":["set"],"allowedValues":[{"self":"https://guffer4.atlassian.net/rest/api/latest/resolution/1","name":"Fixed","id":"1"},{"self":"https://guffer4.atlassian.net/rest/api/latest/resolution/2","name":"Won't Fix","id":"2"},{"self":"https://guffer4.atlassian.net/rest/api/latest/resolution/3","name":"Duplicate","id":"3"},{"self":"https://guffer4.atlassian.net/rest/api/latest/resolution/4","name":"Incomplete","id":"4"},{"self":"https://guffer4.atlassian.net/rest/api/latest/resolution/5","name":"Cannot Reproduce","id":"5"}]},"worklog":{"required":false,"schema":{"type":"array","items":"worklog","system":"worklog"},"name":"Log Work","operations":["add"]}}}]}

as you can see (at the end of string) worklog is in response.

TAGS
AUG Leaders

Atlassian Community Events