Example: User management using REST APIs

Creating a user

Method and URI:

POST "https://192.0.2.5/rest/v1/system/users"

Request body:

{
  "name": "myadmin",
  "password": "P@ssw0rd",
  "user_group": "/rest/v1/system/user_groups/administrators",
  "origin": "configuration"
}

Example curl command:

$ curl -k -X POST \
-b /tmp/auth_cookie \
"https://192.0.2.5/rest/v1/system/users” –d '
{
  "name": "myadmin",
  "password": "P@ssw0rd",
  "user_group": "/rest/v1/system/user_groups/administrators",
  "origin": "configuration"
}'

On successful completion, the switch returns response code 201 Created.

Changing a password

Method and URI:

PUT "https://192.0.2.5/rest/v1/system/users/myadmin"

Request body:

{
  "password": "P@ssw0rd2g"
}

Example curl command:

$ curl -k -X PUT \
-b /tmp/auth_cookie \
"https://192.0.2.5/rest/v1/system/users/myadmin” –d '
{
  "password": "P@ssw0rd2g"
}'

On successful completion, the switch returns response code 200 OK.

Deleting a user

Method and URI:

DELETE "https://192.0.2.5/rest/v1/system/users/myadmin"

Example curl command:

$ curl -k -X DELETE \
-b /tmp/auth_cookie \
"https://192.0.2.5/rest/v1/system/users/myadmin"

On successful completion, the switch returns response code 204 No Content.