Unable to add workload in script runner post function.

Zbyszek August 14, 2020

Hello

I want to increase the time spend on an issue when the issue is changing its status. For that purpose, I'm using script runner post function with following script:

def issueKey = issue.id

def result = put("/rest/api/3/issue/${issueKey}/worklog")
.header('Content-Type', 'application/json')
.body([
timeSpent: '2h'
]).asString()

But always as a result I'm getting "status: 405 - Method Not Allowed".

It happens no matter whether I run it as a ScriptRunner Add-On User or Initiating User.

I've tried similar, external python script with the same user and it worked. When instead of timeSpent I've tried elapsedTime it also worked properly.

Anyone can help, where am I doing a mistake? Or maybe it's not possible to update the timeSpent from scriptRunner?

1 answer

1 accepted

0 votes
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 15, 2020

hi @Zbyszek  the problem is that you are using "put" method to update worklog, but it would work only to update existing worklog.

I will try to describe it little bit. You have an issue object and every log work operation creates new worklog entry, so you can have multiple worklogs on one issue.

  • POST method creates NEW entry
  • PUT method updates EXISTING entry

If it is ok just to add new worklog, you can use:


def result = post("/rest/api/3/issue/${issueKey}/worklog")
.header('Content-Type', 'application/json')
.body([
timeSpent: '1h'
]).asString()
Zbyszek August 16, 2020

Thank you, that worked perfectly :).

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events