Skip to content

Instantly share code, notes, and snippets.

@qvaqvaboo
Last active May 8, 2024 15:17
Show Gist options
  • Save qvaqvaboo/1abbec8054b26dbdd4ae to your computer and use it in GitHub Desktop.
Save qvaqvaboo/1abbec8054b26dbdd4ae to your computer and use it in GitHub Desktop.
JIRA bulk unwatch with your browser only (JS)
// Simple JS snippet to bulk unwatch (stop watching, un-watch) issues in JIRA.
// Written and tested for JIRA 5.2, but should work for all 5+ versions.
// WHAT IT DOES:
// 1. Gets list of issues you watch using JQL search via REST API. You can modify JQL per your needs.
// 2. For each issue found, triggers REST API call to unwatch this issue for current user.
// HOWTO:
// 1. Go to JIRA in your browser, log in.
// 2. Open your browser JavaScript console.
// IMPORTANT: this code snippet will be using your current browser session with JIRA.
// Remmember, that it is insecure to execute any JavaScript code in your browser console if you don't know what it does.
// 3. Copy and past the code block below into your browser JavaScript console.
// 4. Hit ENTER
// 5. Watch the progress.
// IMPORTANT: It only unwatches 50 issues per run, so you might need to run it multiple times.
AJS.$.ajax({
url: '/rest/api/latest/search',
data: {jql:'watcher = currentUser()'},
success: function (response) {
AJS.$.each(response.issues, function(i,issue) {
AJS.$.ajax({
url: '/rest/api/1.0/issues/' + issue.id + '/watchers',
type: 'delete',
success: function () { console.log('Unwatched ' + issue.key); }
});
});
}
});
@TheTestingMuse
Copy link

As a contractor this is a fantastic tool to "clean up" watched items at the end of a contract. Thanks so much for creating it! Do you think it would be possible to add a "where" clause to this to un-watch only "Closed" issues as an example?

There are a couple of example code snippets in the API documentation:

"fields": {
"status": {
"iconUrl": "http://www.example.com/jira//images/icons/statuses/closed.png",
"name": "Closed"
}
}

What do you think?

Copy link

ghost commented Jul 24, 2019

Do you think it would be possible to add a "where" clause to this to un-watch only "Closed" issues as an example?

This is achievable by adjusting the JQL query eg:
jql:'watcher = currentUser() AND status = Closed'

Also - thanks for this neat snippet - just saved me from 500+ manual operations :)

@ggonmar
Copy link

ggonmar commented Jan 12, 2021

This was the only solution I found for my attempts to unwatch tickets via REST API. Deepest kudos to this post, thank you so much!

@rlorenzo
Copy link

Just wanted to give props and thanks! This is still working on JIRA Cloud v8.20.11. Crazy that there isn't a way to do this bulk change without the JS snippet.

@jhult
Copy link

jhult commented May 8, 2024

I completely agree with rlorenzo. So crazy this is required, but it is still working great on Jira Cloud 9.4.15. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment