API Remove User Site Access

How to trigger the switch “Has access on site” via API in Administration > Users > User details in Access section?

We want to disable certain users access but still want to keep the user disabled in the system for next 90days(as per our policy) and in order to reassign users issues,filters… before we delete the user.

I referred to JIRA Cloud Developer REST API documentation.

I tried:
$url = “JIRA_url/user?accountId=yyy”
$body = @{
active = “False”
Invoke-RestMethod -Method PUT -Uri $url -Body $body

I simplified the code above to make it easier. I got the error:
Invoke-RestMethod : The remote server returned an error: (405) Method Not Allowed

Hi @SreckoAnzic,

Have you had a look at the User Management Rest API - I think that might be what you’re after.

Let me know how you go.

1 Like

Hi @mpaisley ,
Thank you for looking into this and appreciate all your help.

The account_id used in below sample is not real.
I just tried for example:
$path = “JIRA.sec”
$encodedCreds = Import-CliXml -Path $path
$url = ‘https://api.atlassian.com/users/6fa2e2453730r901764be83h/manage/lifecycle/disable
$headers = @{ “Authorization” = “Basic $encodedCreds” }
Invoke-RestMethod -Method Post -Uri $url -Headers $headers -ContentType “application/json”

I got the response from PowerShell:
Invoke-RestMethod : {“code”:401,“message”:“Unauthorized”}
At line:5 char:11

  • $result = Invoke-RestMethod -Method Post -Uri $url -Headers $headers …
  •       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I would say that JIRA blocked this function. But this is one of the most important and basic functions for our company.

Thank you!

Looks like API key needs to be created from the admin part as Huy advised me. Thanks both! I will test it out.