# REST API example change password

**URL:** <https://community.f5.com/t/rest-api-example-change-password/59367>\
**Category:** Technical Forums\
**Tags:** big-ip, devops\
**Created:** [November 21, 2019, 2:43pm UTC](https://community.f5.com/t/rest-api-example-change-password/59367 "2019-11-21T14:43:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lowone](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@lowone](https://community.f5.com/u/lowone)\
**Post date:** [November 21, 2019, 2:43pm UTC](https://community.f5.com/t/rest-api-example-change-password/59367/1 "2019-11-21T14:43:55Z")

</div>

I need to change the password for admin and root accounts on our big-ip servers. I found this api end point but need more info on the parameters or a working example.

> **[APIRef\_tm\_auth\_password](https://clouddocs.f5.com/api/icontrol-rest/APIRef_tm_auth_password.html)**

---

<div class="post-metadata">

**Author:** ![Enes\_Afsin\_Al](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/enes_afsin_al/32/15359_2.png) [@Enes\_Afsin\_Al](https://community.f5.com/u/Enes_Afsin_Al)\
**Post date:** [November 23, 2019, 9:51pm UTC](https://community.f5.com/t/rest-api-example-change-password/59367/2 "2019-11-23T21:51:14Z")

</div>

Hi lowone,

[https://cdn.f5.com/websites/devcentral.f5.com/downloads/icontrol-rest-api-user-guide-14-1-0.pdf](https://cdn.f5.com/websites/devcentral.f5.com/downloads/icontrol-rest-api-user-guide-14-1-0.pdf) (page 19)

> **[F5 Cloud Docs](https://clouddocs.f5.com/)**
>
> F5 Cloud Documentation

---

<div class="post-metadata">

**Author:** ![jaikumar\_f5](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@jaikumar\_f5](https://community.f5.com/u/jaikumar_f5)\
**Post date:** [November 24, 2019, 3:19am UTC](https://community.f5.com/t/rest-api-example-change-password/59367/3 "2019-11-24T03:19:48Z")

</div>

Something like below should do the trick,

```tcl
curl -sk -u useraccount -H "Content-Type: application/json" -X PATCH https://hostname/mgmt/tm/auth/user/useraccount -d '{ "password": "newpassword" }'

```

Once above is it will prompt for existing password and the change will reflect. The user will have the newpassword set as password.

If you’d need you can send the existing password in the query too.

```tcl
curl -sk -u useraccount:oldpassword -H "Content-Type: application/json" -X PATCH https://hostname/mgmt/tm/auth/user/useraccount -d '{ "password": "newpassword" }'

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Shahid\_Khan](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Shahid\_Khan](https://community.f5.com/u/Shahid_Khan)\
**Post date:** [April 29, 2020, 9:31pm UTC](https://community.f5.com/t/rest-api-example-change-password/59367/4 "2020-04-29T21:31:29Z")

</div>

Pre-requisite:

1- Admin role user which has authority to change the password

2- user’s username of which password will change

3- New password of the user’s username

User: test

Admin User: f5osadmin

Python: working on 2.7 and 3

```tcl
import requests
from requests.auth import HTTPBasicAuth
import json
import urllib3
 
urllib3.disable_warnings()
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # suppress SSL error
 
def change_password(b, url, creds):
  payload = { }
  payload['password'] = creds[0]
  #print("Payload: ", payload)
  response1 = b.patch(url, data=json.dumps(payload))
  
  #print(response1.content)
  #print(response1.status_code)
  #print(response1.request.body)
   # Return Boolean 
   if response1 .status_code == int(200):
        pass_bool= True
        return pass_bool
    elif response1 .status_code == int(400) or response1 .status_code == int(401) :
       pass_bool= False
       return pass_bool
 
  
###### TO CHANGE Other non admin user PASSWORD ##################
 
creds=["MyNewPassword123!"] # user "test" new password 
b = requests.session()
b.auth = ('f5osadmin', 'f5OsaDm1n!') # F5 admin role user credentials. 
b.verify = False  
b.headers.update({'Content-Type':'application/json'})
if change_password(b, 'https://f5.sik.domain.com/mgmt/tm/auth/user/test', creds): # user test
  print("password change successful")
else:
  print("password change failed")
 
 
###### END TO CHANGE PASSWORD ##################

```

Above is basic python code with few verification in print and which can be enhance with try exception

Hope this will help

---

<div class="post-metadata">

**Author:** ![Chad\_Wise](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/chad_wise/32/33590_2.png) [@Chad\_Wise](https://community.f5.com/u/Chad_Wise)\
**Post date:** [July 16, 2025, 7:39pm UTC](https://community.f5.com/t/rest-api-example-change-password/59367/5 "2025-07-16T19:39:48Z")

</div>

```yaml
---
- name: View and Update user
  hosts: f5
  connection: local
  gather_facts: false

  tasks:

  - name: Login via uri Get token
    tags: basic
    ansible.builtin.uri:
      url: 'https://{{ ansible_host }}/mgmt/shared/authn/login'
      return_content: true
      force_basic_auth: true
      method: POST
      body_format: json
      body: "{ \"username\": \"admin\", \"password\": \"S3cretP@55word!\", \"loginProviderName\": \"tmos\"}"
      headers:
        Content-Type: application/json
      validate_certs: false
    register: token

  - name: Show token
    tags: basic
    debug:
      var: token.json.token.token

  - name: View users
    tags: basic
    ansible.builtin.uri:
      url: 'https://{{ ansible_host }}/mgmt/tm/auth/user/cwise'
      headers:
        Content-Type: application/json
        X-F5-Auth-Token: "{{ token.json.token.token }}"
      method: GET
      return_content: true
      validate_certs: false
    register: users

  - name: Show user cwise
    tags: basic
    debug:
      var: users

  - name: Update user passwd
    ansible.builtin.uri:
      url: 'https://{{ ansible_host }}/mgmt/tm/auth/user/cwise'
      headers:
        Content-Type: application/json
        X-F5-Auth-Token: "{{ token.json.token.token }}"
      method: PATCH
      body: "{\"password\": \"n3w5ecret!\"}"
      body_format: json
      validate_certs: false

```

An Ansible example
