<!-- Generated by scripts/build-docs.js. Edit docs/swagger.yaml or docs/guides/, then run `npm run docs:build`. -->

# Update a user's profile

`POST https://marketplace-api.sequifi.com/v1/users`

Module: Users · operationId: `updateUserProfile` · Auth: `Authorization: Bearer <token>`
Web page: https://apidocs.sequifi.com/#/api/update-user-profile

Updates an existing, active employee's personal details: name, sex, date of birth, email, mobile number, home address, emergency contact, your company's custom personal fields and admin-only fields. It never creates a user. Sending `employee_personal_detail` replaces the employee's entire set of custom field values, so always send the full array.

**Before you call:**

- Find the user's `id` with `GET /v1/users?status=active`. Only active users (`status_id` 1) can be updated; anyone else returns `404`.
- Get custom field ids from `GET /v1/custom-fields?type=employee`, and admin-only field ids from `GET /v1/custom-fields?type=employee_admin`.
- To change custom fields, read the current `employee_personal_detail` from `GET /v1/users/{id}`, change the values you need, and send the whole array back.

**What happens:**

- Only the fields you send change. Fields you leave out keep their values.
- `first_name`, `middle_name`, `last_name`, `dob`, `sex`, `email` and `mobile_no` cannot be cleared: `null` (or the string `"null"`) counts as not sent.
- Home address and emergency contact fields are cleared by sending `null`.
- `employee_personal_detail` replaces the stored array. A field you leave out is removed, and `null` removes them all.
- `employee_admin_only_fields` is merged by `id`: only the fields you send change, and the rest keep their values. An unknown or deleted id returns `400` and nothing is saved. `null` is not allowed. If the employee's saved admin-only fields are in a format the API can't read, the request returns `409` and nothing is saved; update them in Sequifi instead.
- A new `email`, `mobile_no`, `first_name` or `last_name` is also copied to the employee's hiring records.
- Each changed field is recorded in the employee's profile history, attributed to the "Marketplace API" system user.
- Fields this endpoint does not handle (for example `office_id`, `position_id` or `status_id`) are ignored without an error.

**Idempotency and retries:**

- Sending the same body again is safe: nothing changes except `updated_at`.
- On `409`, another update to the same employee was in progress. Retry the same request.

**Formats:**

- `user_id` is a positive integer or a string of digits.
- `email` must look like `name@domain.tld` and must not be in use by another active employee, or by a hiring record or lead that is not this employee's.
- `mobile_no` needs at least 10 digits and has the same uniqueness rule as `email`. Numbers are compared exactly as stored, so `512-555-0142` and `5125550142` count as different numbers. Use one format everywhere.
- `dob` is `YYYY-MM-DD` and must be a real date.
- `sex` is `male`, `female` or `other`, in lowercase.
- Each `employee_personal_detail` item needs an integer `id` (a JSON number, not a string) and a `value` key, which may be `null`. Ids must not repeat.
- In the response, `dob` is `YYYY-MM-DD` and `created_at` / `updated_at` are `YYYY-MM-DD HH:MM:SS` in UTC with no zone marker. This differs from the ISO format `GET /v1/users` returns for the same fields.

**Errors:**

- `400` `Validation failed`, with one message per field in `data.errors`.
- `400` `Invalid or missing user_id in request body`, `No fields provided to update`, `Invalid or missing JSON body`, `Request body must be a JSON object`, or `Duplicate value detected. Please ensure all unique fields have distinct values.`
- `404` `User <id> not found` (no such user, or the user is not active), or `User <id> not found or no longer active`.
- `409` concurrent update. Retry.
- `401` when the token is missing, malformed, expired or revoked. It is rejected before the request is processed, so the body is only `{"message":"Unauthorized"}`, with no `status` or `data`.
- A duplicate `email` or `mobile_no` message names the employee who already uses the value. Do not show these messages to end users as they are.

**Common mistakes:**

- Using this endpoint to add a person. Hire through `POST /v1/onboarding` and `PUT /v1/onboarding/hire`.
- Sending only the custom field you changed, which deletes the others.
- Sending custom field ids as strings (`"2"`), which fails validation.
- Updating a terminated or dismissed user.

**Related:**

- `POST /v1/users/{id}/transfer` changes the office; `POST /v1/users/{id}/position` changes the position.
- `GET /v1/users/{id}` confirms the change.

## Request body

- `user_id` (integer, **required**): Id of the active user to update, from `GET /v1/users`. Minimum: 1. Example: `4821`.
- `first_name` (string): First name. Cannot be cleared. Example: `Alex`.
- `middle_name` (string): Middle name. Cannot be cleared. Example: `J`.
- `last_name` (string): Last name. Cannot be cleared. Example: `Morgan`.
- `sex` (string): Lowercase. Cannot be cleared. One of: `male`, `female`, `other`. Example: `female`.
- `dob` (string (date)): Date of birth, YYYY-MM-DD. Cannot be cleared. Example: `1990-01-15`.
- `email` (string (email)): Must be unused by any other active employee, hiring record or lead. Cannot be cleared. Example: `alex.morgan@example.com`.
- `mobile_no` (string): At least 10 digits. Same uniqueness rule as `email`, compared exactly as stored. Cannot be cleared. Example: `5125550142`.
- `home_address` (string, nullable): Formatted single-line home address. `null` clears it. Example: `1200 Congress Ave, Austin, TX 78701, USA`.
- `home_address_line_1` (string, nullable): Street line. `null` clears it. Example: `1200 Congress Ave`.
- `home_address_line_2` (string, nullable): Apartment or suite line. `null` clears it.
- `home_address_city` (string, nullable): City (up to 100 characters). Example: `Austin`.
- `home_address_state` (string, nullable): State. Send the 2-letter code; the value is not checked. Example: `TX`.
- `home_address_zip` (string, nullable): ZIP code (up to 100 characters). Example: `78701`.
- `home_address_lat` (string, nullable): Latitude, as a string.
- `home_address_long` (string, nullable): Longitude, as a string.
- `home_address_timezone` (string, nullable): Time zone of the home address.
- `emergency_contact_name` (string, nullable): Emergency contact's name. `null` clears it.
- `emergency_contact_relationship` (string, nullable): Relationship to the employee.
- `emergency_phone` (string, nullable): Emergency contact's phone number.
- `emergency_address_line_1` (string, nullable): Emergency contact's street line.
- `emergency_address_line_2` (string, nullable): Emergency contact's apartment or suite line.
- `emergency_address_lat` (string, nullable): Latitude, as a string.
- `emergency_address_long` (string, nullable): Longitude, as a string.
- `emergency_address_timezone` (string, nullable): Time zone of the emergency contact's address.
- `employee_personal_detail` (array of object): Your company's custom personal fields. Replaces the stored list: send every field you want to keep. `null` removes them all. Get ids from `GET /v1/custom-fields?type=employee`.
  - `id` (integer, **required**): Custom field id, as a JSON number. Minimum: 1.
  - `value` (any, nullable, **required**): The value to store, usually a string. `null` is allowed.
  - `field_name` (string): Optional label, stored with the value.
  - `field_type` (string): Optional field type, stored with the value.
- `employee_admin_only_fields` (array of object): Your company's admin-only custom fields. Merged by `id`: send only the fields you want to change. The stored `field_name` comes from the field definition. Get ids from `GET /v1/custom-fields?type=employee_admin`.
  - `id` (integer, **required**): Admin-only field id, as a JSON number. Minimum: 1.
  - `value` (any, nullable, **required**): The value to store, usually a string. `null` is allowed.

Example (admin_only_fields): Set an admin-only field

```json
{
  "user_id": 4821,
  "employee_admin_only_fields": [
    {
      "id": 1,
      "value": "Rookie Rep"
    }
  ]
}
```

Example (contact_details): Change email and mobile number

```json
{
  "user_id": 4821,
  "email": "alex.morgan@example.com",
  "mobile_no": "5125550142"
}
```

Example (custom_fields): Update custom fields (send the full list)

```json
{
  "user_id": 4821,
  "employee_personal_detail": [
    {
      "id": 1,
      "value": "1991-05-15"
    },
    {
      "id": 2,
      "value": "Alex"
    }
  ]
}
```

## Example request

```bash
curl -X POST "https://marketplace-api.sequifi.com/v1/users" \
  -H "Authorization: Bearer $SEQUIFI_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"user_id":4821,"employee_admin_only_fields":[{"id":1,"value":"Rookie Rep"}]}'
```

## Responses

### 200: Profile updated

- `status` (integer): The HTTP status code, repeated. Example: `200`.
- `message` (string): Short text. Wording varies by endpoint; branch on the HTTP status, not on this text. Example: `success`.
- `data` (object)
  - `requestedBy` (string): Name of the API credential your token belongs to.
  - `data` (object): The updated user. In the rare case the user cannot be read back after saving, this holds only `id`; the update was still saved.
    - `id` (integer): User id.
    - `employee_id` (string, nullable): Your company's employee number.
    - `first_name` (string): First name.
    - `middle_name` (string, nullable): Middle name.
    - `last_name` (string): Last name.
    - `sex` (string, nullable): `male`, `female` or `other`.
    - `dob` (string, nullable): Date of birth, YYYY-MM-DD.
    - `email` (string): Email address.
    - `mobile_no` (string, nullable): Mobile number as stored.
    - `home_address` (string, nullable): Formatted single-line home address. The response also returns every other `home_address_*` field, including `_lat`, `_long` and `_timezone`.
    - `emergency_contact_name` (string, nullable): Emergency contact's name. The response also returns the other `emergency_*` fields.
    - `employee_personal_detail` (array of object): The stored custom fields, as sent.
    - `is_manager` (integer): 1 if the user is a manager.
    - `status_id` (integer): Always 1 (only active users can be updated).
    - `office_id` (integer, nullable): Current office id.
    - `office_name` (string, nullable): Current office name.
    - `state_code` (string, nullable): Work state code.
    - `created_at` (string): `YYYY-MM-DD HH:MM:SS`, UTC.
    - `updated_at` (string): `YYYY-MM-DD HH:MM:SS`, UTC.

```json
{
  "status": 200,
  "message": "User profile updated successfully",
  "data": {
    "requestedBy": "acme",
    "data": {
      "id": 4821,
      "employee_id": "EMP-1042",
      "first_name": "Alex",
      "middle_name": null,
      "last_name": "Morgan",
      "sex": "female",
      "dob": "1990-01-15",
      "email": "alex.morgan@example.com",
      "mobile_no": "5125550142",
      "home_address": "1200 Congress Ave, Austin, TX 78701, USA",
      "home_address_line_1": "1200 Congress Ave",
      "home_address_line_2": null,
      "home_address_city": "Austin",
      "home_address_state": "TX",
      "home_address_zip": "78701",
      "home_address_lat": null,
      "home_address_long": null,
      "home_address_timezone": null,
      "emergency_contact_name": "Jamie Morgan",
      "emergency_contact_relationship": "Sibling",
      "emergency_phone": "5125550199",
      "emergency_address_line_1": null,
      "emergency_address_line_2": null,
      "emergency_address_lat": null,
      "emergency_address_long": null,
      "emergency_address_timezone": null,
      "employee_personal_detail": [
        {
          "id": 1,
          "value": "1991-05-15"
        },
        {
          "id": 2,
          "value": "Alex"
        }
      ],
      "is_manager": 0,
      "status_id": 1,
      "office_id": 31,
      "created_at": "2024-01-15 10:00:00",
      "updated_at": "2026-10-08 15:04:05",
      "state_code": "TX",
      "office_name": "Austin"
    }
  }
}
```

### 400: Invalid body or failed validation

Example (missing_user_id): user_id missing or not a positive integer

```json
{
  "status": 400,
  "message": "Invalid or missing user_id in request body",
  "data": {}
}
```

### 401: Missing, malformed, expired or revoked token. Rejected before processing, so the body has only `message`.

```json
{
  "message": "Unauthorized"
}
```

### 404: No active user with that id

```json
{
  "status": 404,
  "message": "User 4821 not found",
  "data": {}
}
```

### 409: Another update to the same user was in progress. Retry.

```json
{
  "status": 409,
  "message": "Conflict: request could not be completed due to a concurrent update. Please retry.",
  "data": {}
}
```

### 500: Internal server error

```json
{
  "status": 500,
  "message": "Internal Server Error",
  "data": {}
}
```
