Skip to content

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 }

PUT users/:id

Update a user specified by id.

Restrictions

  • 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 to false.
  • Only the admin role can change a user's role via the role field.

Resource Information

Request formats JSON
Requires authentication? Yes
DeletedAt Boolean

Fields

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

Example User Request

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"
}'

Example Response

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"
}

Example Admin Request

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
}'

Example Response

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
}
Clone this wiki locally