# API Remove User Site Access

**URL:** <https://community.developer.atlassian.com/t/api-remove-user-site-access/48114>\
**Category:** Jira Cloud\
**Tags:** powershell, atlassian-guard, identity, jira-cloud, rest-api\
**Created:** [May 19, 2021, 8:54pm UTC](https://community.developer.atlassian.com/t/api-remove-user-site-access/48114 "2021-05-19T20:54:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SreckoAnzic](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@SreckoAnzic](https://community.developer.atlassian.com/u/SreckoAnzic)\
**Post date:** [May 19, 2021, 8:54pm UTC](https://community.developer.atlassian.com/t/api-remove-user-site-access/48114/1 "2021-05-19T20:54:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mpaisley](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/mpaisley/32/54538_2.png) [@mpaisley](https://community.developer.atlassian.com/u/mpaisley)\
**Post date:** [May 25, 2021, 3:57am UTC](https://community.developer.atlassian.com/t/api-remove-user-site-access/48114/2 "2021-05-25T03:57:27Z")

</div>

Hi @SreckoAnzic,

Have you had a look at the User Management Rest API - I think that might be what you’re after.  
[https://developer.atlassian.com/cloud/admin/user-management/rest/api-group-users/#api-users-account-id-manage-lifecycle-disable-post](https://developer.atlassian.com/cloud/admin/user-management/rest/api-group-users/#api-users-account-id-manage-lifecycle-disable-post)

Let me know how you go.  
Cheers,  
Mel

---

<div class="post-metadata">

**Author:** ![SreckoAnzic](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@SreckoAnzic](https://community.developer.atlassian.com/u/SreckoAnzic)\
**Post date:** [May 28, 2021, 5:25pm UTC](https://community.developer.atlassian.com/t/api-remove-user-site-access/48114/3 "2021-05-28T17:25:59Z")

</div>

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](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!

---

<div class="post-metadata">

**Author:** ![SreckoAnzic](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@SreckoAnzic](https://community.developer.atlassian.com/u/SreckoAnzic)\
**Post date:** [June 8, 2021, 11:58pm UTC](https://community.developer.atlassian.com/t/api-remove-user-site-access/48114/4 "2021-06-08T23:58:40Z")

</div>

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