Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How deactivate user (as rest parameter) via scriptrunner


I would like to know if there is a way to deactivate a user using scriptrunner and pass username via the rest endpoint ?

Something like:  jiraBaseURL/rest/scriptrunner/latest/custom/deactivateUser/?userName=USERNAME

I saw this documentation: but it's for deactivating users that are inactive. Plus this code is not custom endpoint.

I'm a beginner on this area. I only have a skeleton code:

import com.atlassian.jira.component.ComponentAccessor
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

import javax.servlet.http.HttpServletRequest

@BaseScript CustomEndpointDelegate delegate

deactivateUser(httpMethod: "GET", groups: ["jira-administrators"]) { queryParams, body, HttpServletRequest request ->
def userName = request.getParameter("userName")
if (userName) {

// Deactivate userName
// Test if success
// return Response.ok("SUCCESS").build()
// Test if failed (example: if user is project lead)
// return Response.ok("FAILED").build()
return Response.noContent().build()

Can someone help me to build that code ? 

Thank you very much.


1 answer

0 votes

You're nearly there. The code you linked to shows pretty well how to deactivate a user, I think where you're struggling is how to get a user from query parameters. Something like this should do:

import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.UserWithAttributes
import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUsers
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

import javax.servlet.http.HttpServletRequest

@BaseScript CustomEndpointDelegate delegate

deactivateUser(httpMethod: "GET", groups: ["jira-administrators"]) { MultivaluedMap queryParams, body, HttpServletRequest request ->
def userKey = queryParams.getFirst("userKey") as String
UserService userService = ComponentAccessor.getComponent(UserService)
def crowdService = ComponentAccessor.getComponent(CrowdService)
UserWithAttributes user = crowdService.getUserWithAttributes(userKey)
def updateUser = ApplicationUsers.from(ImmutableUser.newUser(user).active(false).toUser())
def validationResult = userService.validateUpdateUser(updateUser)
if (validationResult.isValid()) {
return Response.ok(new JsonBuilder("Deactivated $userKey").toString()).build()
} else {
log.error "Failed to update user with key $userKey"
log.error validationResult.errorCollection
return Response.status(Response.Status.BAD_REQUEST).build()

Notably, that will fail for users who are project leads, but it should log the error so that you can discern the source of the problem.

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events