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

Unable to add workload in script runner post function. Edited

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

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()

Thank you, that worked perfectly :).

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
Community showcase
Published in Jira Software

How to create Jira issus from Excel file?

When to use CSV importer When managing your processes in Jira, there are many occasions where you need to create a lot of tasks. Creating them one by one will cost you a lot of time and effort and i...

3,729 views 15 27
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