Update User

Endpoint

URL: /:projectId/users/:userId

Method: PATCH

Authentication Required: Yes (Access Token in Authorization Header)


Description

This endpoint allows clients to update user details. The update can include username, location, or other user attributes. The request must be authenticated.


Request

Path Parameters

ParameterTypeRequiredDescription
projectIdstringYesThe project ID associated with the request.
userIdstringYesThe ID of the user to update.

Headers

HeaderTypeRequiredDescription
AuthorizationstringYesBearer token for authentication.

Body Parameters

ParameterTypeRequiredDescription
namestringNoNew name for the user.
usernamestringNoNew username for the user. Must be sanitized.
avatarstring (URL)NoURL of the user’s new avatar.
biostringNoShort biography of the user.
birthdatestring (ISO Date)NoUser’s birthdate in ISO format.
locationobjectNoLocation data, requires longitude and latitude.
metadataobjectNoCustom metadata for the user.

Example Request

PATCH /12345/users/67890
Content-Type: application/json
Authorization: Bearer <ACCESS_TOKEN>
 
{
  "username": "new_username",
  "location": { "longitude": 34.05, "latitude": -118.25 },
  "metadata": { "theme": "dark" }
}

Response

Success Response (200 OK)

{
  "id": "67890",
  "username": "new_username",
  "name": "John Doe",
  "avatar": "https://example.com/avatar.jpg",
  "bio": "New bio text",
  "birthdate": "1990-01-01T00:00:00.000Z",
  "location": {
    "type": "Point",
    "coordinates": [34.05, -118.25]
  },
  "metadata": {
    "theme": "dark"
  }
}

Error Responses

Missing or Invalid Data (400 Bad Request)

{
  "error": "Missing required data"
}

User Not Found (404 Not Found)

{
  "error": "User not found"
}

Server Error (500 Internal Server Error)

{
  "error": "Server error"
}

Notes

  • Authentication is required to update user details.
  • Only fields that are present in the request body will be modified.
  • If a new username is provided, it will be sanitized before updating.
  • Location data should be provided as an object containing longitude and latitude.
  • Webhook validateUserUpdated is triggered before updating the user.