Skip to main content
PUT
/
api
/
usuarios
/
:id
/
rol
Update User Role
curl --request PUT \
  --url https://api.example.com/api/usuarios/:id/rol \
  --header 'Content-Type: application/json' \
  --data '
{
  "role": "<string>"
}
'
{
  "message": "<string>",
  "usuario": {
    "id": "<string>",
    "persona_id": 123,
    "role": "<string>",
    "created_at": "<string>"
  }
}

Overview

Changes the role of a user without modifying other user properties. This is useful for promoting or demoting users between admin and assistant roles.
Admin OnlyThis endpoint requires authentication and the admin role.

Path Parameters

id
string
required
The Supabase authentication UUID of the user

Request Body

role
string
required
The new role for the user. Must be either admin or asistente.

Response

message
string
Success message: “Rol actualizado”
usuario
object
The updated user object

Example Request

cURL
curl -X PUT http://localhost:3000/api/usuarios/a1b2c3d4-e5f6-7890-abcd-ef1234567890/rol \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "role": "admin"
  }'
JavaScript
const response = await fetch(
  'http://localhost:3000/api/usuarios/a1b2c3d4-e5f6-7890-abcd-ef1234567890/rol',
  {
    method: 'PUT',
    headers: {
      'Authorization': `Bearer ${adminToken}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      role: 'admin'
    })
  }
);

Example Response

200 OK
{
  "message": "Rol actualizado",
  "usuario": {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "persona_id": 5,
    "role": "admin",
    "created_at": "2024-03-01T10:00:00.000Z"
  }
}

Error Responses

{
  "message": "Role es obligatorio"
}
The role field was not provided in the request body.
{
  "message": "Usuario no encontrado"
}
The user with the specified ID does not exist.

Use Cases

  • Promoting an assistant to admin
  • Demoting an admin to assistant
  • Correcting incorrectly assigned roles
Source: /home/daytona/workspace/source/src/routes/usuarios.routes.js:215

Build docs developers (and LLMs) love