Delete all worklogs from an issue using Jira Automation with REST API

36 comments

Alex Ziegltrum
Contributor
April 27, 2023

Found out, when using the "validate" function in an automation rule, you can't use a smart value for your Authentication. With this, the validation works.

image.png

Now, I am focusing on identifying a certain worklog, which in my case is the last one created / updated as the trigger for my autom. rule. 

Susanne is helping me on in this thread Time tracking to slack (atlassian.com)

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 27, 2023
Dave Zuzak February 27, 2024

I hate to bring an old thread back, but hoping my ask helps someone else. I'm getting the 400 error depicted.  Thoughts?

Manual Trigger 1.PNGManual Trigger 2.PNGManual Trigger 3.PNG

Like Vikrant Yadav likes this
Tara
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 24, 2024

@Alex Koxaras _Relational_ Thank you for your work to document this article and share it with the community.

To extend on existing suggestions from https://community.atlassian.com/t5/Jira-Software-articles/Delete-all-Tempo-worklogs-from-an-issue-using-Jira-Automation/bc-p/2647017#M12703 to only fetch and delete worklogs that were created before a specific period (e.g. start of the month), the following syntax can be used:

?maxResults=5000&startedBefore={{#now}}func=minusMonths(1).endOfMonth, format="toMillis"{{/}}
Bill Sheboy
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.
March 25, 2024

Hi @Tara __ 

Thanks for your ideas extending this for Tempo worklogs.  Does that URL parameter for startedBefore encode to a UNIX Timestamp (i.e., milliseconds after 1 Jan 1970)?

 

For those doing this filtering with the built-in Jira REST API rather than the Tempo one, the function takes a UNIX Timestamp in milliseconds.  https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-issue-issueidorkey-worklog-get 

And so to use the startedAfter or startedBefore parameters for a different field than {{now}}, the math difference must be performed relative to the UNIX Epoch.  To accomplish this, you may save the time value for the UNIX Epoch in a variable and then perform the difference.

  • create variable:
    • name: varUnixEpoch
    • smart value: {{now.withYear(1970).withDayOfYear(1).toDateTimeAtStartOfDay}}
  • get your parameter, for example relative to {{issue.created}} convert the values and diff()
    • {{varUnixEpoch.toDate.diff(issue.created).millis}}

Kind regards,
Bill

Like Tara likes this
Tara
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 25, 2024

@Bill Sheboy Thanks for the suggestion! I think that's another great example to base the timestamp off the issue's created date and the more options people have to work with, the better chances it has of serving all the various use cases.

Though my inspiration came from the Tempo worklog article, this timestamp was applied to Jira worklogs and the full API I used was:

https://{SITENAME}.atlassian.net/rest/api/3/issue/{{issue.id}}/worklog?maxResults=5000&startedBefore={{#now}}func=minusMonths(1).endOfMonth, format="toMillis"{{/}}

{#now} with a formatting of "toMillis" should give a timestamp in milliseconds relative to UNIX Epoch. minusMonths(1) and .endOfMonth are other auxillary functions to align to a specific window. Hope this can help anyone looking to enhance automation to delete Jira worklogs. 

Like Bill Sheboy likes this
Bill Sheboy
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.
March 26, 2024

Thanks, @Tara __ 

I tried that for a date / time field and it produced the same result as you see for {{now}}, so the variable and diff do not appear to be needed (unless the date calculation scenario is more complicated).  Do you have a link to the Tempo worklog article as I did not see that example on the REST API doc page for Tempo?

I wish features like this were better documented for rule handling :^)

 

Like Tara likes this
Tara
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2024

@Bill Sheboy This is the article for cleaning up Tempo worklogs using their APIs https://community.atlassian.com/t5/Jira-Software-articles/Delete-all-Tempo-worklogs-from-an-issue-using-Jira-Automation/bc-p/2647017#M12703 . The linked comment also shows how you can provide smart values to hone in on a specific time range:

https://api.tempo.io/4/worklogs/issue/{{issue.id}}?from=2019-12-01&to={{now.minusMonths(1).endOfMonth.jiraDate.urlEncode}}
Like Bill Sheboy likes this
mummareddy supriya
Contributor
June 17, 2024

@Alex Ziegltrum I have to delete the worklog after cloning the Epic issues using automation rules in jira

I Applied this  Automation Rule ,In place of webhook url i used https://your-domain.atlassian.net/rest/api/3/issue/projectkey/worklogid. in Header i provided useremail:personal token .but  its not working  and i'm facing below error when i gone through the logs ,may i know the reason please . Thanks in advance error.PNGheader.PNG

Why header is not allowing Delete option ,If any one have idea on this issue please let me know please .thanks in advance

Alex Ziegltrum
Contributor
June 17, 2024

Hi @mummareddy supriyaas it seems to me, you might need to check the endpoint, you want to use. I am referring to https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-issue-issueidorkey-worklog-id-delete

 

  

 

mummareddy supriya
Contributor
June 17, 2024

@Alex Ziegltrum Followed same url as you provided ,Delete 

/rest/api/3/issue/{issueIdOrKey}/worklog/{id} this is the endpoint i'm using .But still facing above 401 error .please guide me here if anyone knows the issue .thankshttps://community.atlassian.com/t5/Jira-articles/Delete-all-worklogs-from-an-issue-using-Jira-Automation-with/bc-p/2728348#M14829 

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events