-
Notifications
You must be signed in to change notification settings - Fork 7
put users id
Harmun edited this page May 16, 2019
·
4 revisions
put | /users/:id | User | Update a user specified by id. User must the user to whom the token was issued | At least one or any combination of { userName, pssword, deletedAt } | { id, userName, dateCreated } |
Update a user specified by id.
- Users can only manipulate data for their own ID , unless they have the admin user role.
- The id parameter must be numeric.
- At least one parameter is required.
- Only the admin role can un-delete a user by setting the
deleteAt
field tofalse
. - Only the admin role can change a user's role via the
role
field.
Request formats | JSON |
Requires authentication? | Yes |
DeletedAt | Boolean |
Name | Required | Description | Role | Example |
---|---|---|---|---|
userName | optional | The created user's username | user | "SteveRogers1918" |
pssword | optional | The password that will be used to authenticate the user | user | "bucky4ever" |
deletedAt | optional | Un-deletes the user. | admin |
true or false
|
role | optional | Changes the user role. | admin |
user or admin
|
If you're a user and wanted to update the username and password simultaneously:
curl -X PUT \
http://localhost:3000/users/10 \
-H 'Authorization: Bearer 123testtoken123' \
-H 'Content-Type: application/json' \
-H 'Host: localhost:3000' \
-d '{
"userName": "PeterParkour",
"pssword": "spiderbyte"
}'
The updated user is returned as an object like this, note the lack of password field even if the password was updated:
{
"id": 9,
"userName": "PeterParkour",
"dateCreated": "2019-05-16T09:39:19.000Z"
}
If you're an admin and wanted to update the user's role
, userName
and un-delete them:
curl -X PUT \
http://localhost:3000/users/9 \
-H 'Authorization: Bearer 123testtoken' \
-H 'Content-Type: application/json' \
-H 'Host: localhost:3000' \
-d '{
"userName": "spiderperson",
"role": "admin",
"deletedAt": false
}'
Note the role
and deleteAt
fields that are returned for admins:
{
"id": 9,
"userName": "spiderperson",
"role": "user",
"dateCreated": "2019-05-14T10:01:56.000Z",
"deletedAt": null
}