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

# Create or replace an onboarding record

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

Module: Onboarding · operationId: `createOnboardingEmployee` · Auth: `Authorization: Bearer <token>`
Web page: https://apidocs.sequifi.com/#/api/create-onboarding-employee

Creates an onboarding record in Draft for a person you plan to hire, and copies the position's default pay onto it. Nothing is sent to the person: send the offer with `POST /v1/onboarding/{id}/send-offer`. Sending `onboarding_id` turns the call into a full replace of that record, which overwrites every field, including the ones you leave out.

**Before you call:**

- Pick `position_id` and `sub_position_id` from `GET /v1/positions`. The sub-position decides the pay that is copied and the offer letter template used later. If you leave it out, `position_id` is used for both.
- Pick `office_id` from `GET /v1/locations`. Archived offices are refused on create.
- Get allowed custom field names and options from `GET /v1/custom-fields?type=onboarding`.
- Get `recruiter_id` and `manager_id` from `GET /v1/users`. The offer letter is sent as the recruiter (or, without one, the manager), and that name is printed on it. These ids are stored without being checked, so make sure they exist.
- Check that the person is not already in Sequifi: `GET /v1/onboarding?email=` and `GET /v1/users?email=`, comparing the email exactly. An existing match on email or mobile number blocks the create.
- Validate the email address and dates yourself. The API does not check the email format, and a malformed date is most likely rejected with `500`.

**What happens:**

Create (no `onboarding_id`) returns `201`:

- The record is created with `status_id` 8 (Draft) and a new onboarding id string such as `ONB0012` (prefix set by your company, `ONB` by default).
- The position's pay is copied onto the record: wages, commissions, upfronts (effective today in UTC), overrides, withholding and deductions. The counts come back in the response.
- `department_id` comes from the position when you leave it out. State and city come from the office.
- Nothing else happens: no email, no candidate update, no team membership.

Replace (with `onboarding_id`) returns `200`:

- Every field is overwritten from the body. Leaving out `manager_id`, `recruiter_id`, `team_id`, `lead_id` or `end_date` sets it to null. Leaving out `sub_position_id` sets it to `position_id`.
- The record's pay is deleted and copied again from the position. Any pay an admin set on this record in the app is lost.
- `custom_fields`, `work_email` and `additional_locations` are replaced only when the key is in the body. Send `[]` to clear one.
- It works on any record: one whose offer was already sent (the sent letter does not change) and one already hired (the user does not change).
- Safe practice: read the record with `GET /v1/onboarding/{id}`, change what you need, and send the complete record back, including every optional field you want to keep. Do not use it on records that already have an offer out or are hired.

**Idempotency and retries:**

- A create is not idempotent. Repeating a create that already succeeded returns `400 Email or mobile number already exists.` without the id. Find the record with `GET /v1/onboarding?email=` (or `GET /v1/users?email=` if it was already hired) and compare the email exactly.
- After a timeout or network error, check for the record before you retry.
- `503 Server is busy, please retry.` means nothing was created. Retry after a short wait.
- Two creates for the same person sent at the same moment can both succeed. Send one person at a time.
- A replace with the same complete body can be repeated safely.

**Formats:**

- `mobile_no`: exactly 10 digits, no spaces or symbols. A JSON number also works.
- `start_date` and `end_date`: `YYYY-MM-DD`.
- `custom_fields`: an array of single-key objects, for example `[{"Employment Type": "Full Time"}]`. Each name must be an onboarding custom field, and a field with options needs one of its option labels. All entries are merged into one object, which `GET /v1/onboarding` returns as a JSON string.
- `work_email`: `[{"email": "alex@work.example.com"}]`. `additional_locations`: `[{"state_id": 5, "office_id": 12}]`.
- `employee_id` in the response is the onboarding id string, not the user's employee id.
- The response key is `requested_by` here, but `requestedBy` on the GET routes.

**Errors:**

- `400 first_name, last_name, email, mobile_no are required.` and `400 position_id, office_id, start_date are required.`
- `400 mobile_no must be exactly 10 digits and must not contain characters.`
- `400 Invalid custom field(s)` (with `data.invalid_fields`, `data.allowed_fields`) and `400 Invalid value for custom field '<name>'` (with `data.provided_value`, `data.allowed_values`).
- `400 Email or mobile number already exists.`: a user or another onboarding record (hired or not) has this email or mobile number.
- `400 Additional email <email> already exists.`
- `400 Position with id <n> not found.`: missing, or not fully set up (create only). The id named is the sub-position when you sent one.
- `400 Department with id <n> not found.`, `400 Office with id <n> not found.`, `400 Additional location office_id <n> not found.`, `400 additional_locations[n].office_id is required.`
- `400 <position name> has no milestone_schema configured; cannot seed default upfronts.` and `400 A required field is missing. Please ensure the position is fully configured.`: the position's setup is incomplete. Ask your company admin to finish it.
- `400 Invalid onboarding_id. Must be a positive integer.` and `404 Onboarding record with id <n> not found.` (replace only).
- `400 Invalid or missing JSON body`
- `503 Server is busy, please retry.`

**Common mistakes:**

- Leaving out `sub_position_id`. The record then uses `position_id`, which may have no offer letter template, so send-offer fails with `TEMPLATE_NOT_MAPPED`.
- Sending only the changed fields with `onboarding_id`. The others are cleared and pay is reset.
- Using `team_id` to put someone on a team. It is stored as a label only. Use `POST /v1/teams` after hire.
- Re-onboarding someone who was onboarded before. Any earlier onboarding record or user with the same email or mobile number blocks the create.

**Related:**

- `POST /v1/onboarding/{id}/send-offer` sends the offer letter.
- `GET /v1/onboarding/{id}` reads the record back.
- `PUT /v1/onboarding/hire` creates the user once the offer is accepted.

## Request body

- `onboarding_id` (integer, nullable): Leave out (or send null) to create. Set it to replace that whole record; send every field you want to keep. Example: `4821`.
- `first_name` (string, **required**): First name. Not trimmed. Example: `Alex`.
- `last_name` (string, **required**): Last name. Not trimmed. Example: `Morgan`.
- `email` (string, **required**): Personal email. The offer letter goes here. Must not match an existing user or onboarding record. The format is not checked. Example: `alex.morgan@example.com`.
- `mobile_no` (string, **required**): Exactly 10 digits. Must not match an existing user or onboarding record. Example: `5125550148`.
- `position_id` (integer, **required**): Position id from `GET /v1/positions`. Example: `14`.
- `sub_position_id` (integer, nullable): Sub-position id. Decides the pay copied and the offer letter template. Defaults to `position_id`. Not checked against `position_id`. Example: `22`.
- `office_id` (integer, **required**): Office id from `GET /v1/locations`. Archived offices are refused on create. Example: `7`.
- `start_date` (string (date), **required**): Agreement start date, `YYYY-MM-DD`. Validate it before sending. Example: `2026-11-02`.
- `end_date` (string (date), nullable): Agreement end date, `YYYY-MM-DD`. Set to null on replace when left out.
- `department_id` (integer, nullable): Taken from the position when left out. Send it only to use a different department; it must exist. Example: `3`.
- `manager_id` (integer, nullable): Manager's user id. Not checked. Set to null on replace when left out. Example: `312`.
- `recruiter_id` (integer, nullable): Recruiter's user id. The offer letter is sent as this user. Not checked. Set to null on replace when left out. Example: `57`.
- `lead_id` (integer, nullable): Candidate id from `GET /v1/candidates`, kept as a link. The candidate is not changed. Not checked. Example: `1093`.
- `team_id` (integer, nullable): Stored as a label only. It does not place the person on a team. Not checked.
- `additional_locations` (array of object): Extra offices. On replace, sent only when present; `[]` clears them.
  - `state_id` (integer): State id. Not checked. Example: `5`.
  - `office_id` (integer, **required**): Office id. Must exist. Example: `12`.
- `work_email` (array of object): Work emails. Each must not already belong to a user or onboarding record. On replace, sent only when present.
  - `email` (string): Work email address. Example: `alex@work.example.com`.
- `custom_fields` (array of object): Onboarding custom fields as single-key objects, for example `[{"Employment Type": "Full Time"}]`. Names come from `GET /v1/custom-fields?type=onboarding`. On replace, sent only when present.

Example (create): Create a Draft record

```json
{
  "first_name": "Alex",
  "last_name": "Morgan",
  "email": "alex.morgan@example.com",
  "mobile_no": "5125550148",
  "position_id": 14,
  "sub_position_id": 22,
  "office_id": 7,
  "start_date": "2026-11-02",
  "recruiter_id": 57,
  "manager_id": 312,
  "lead_id": 1093
}
```

Example (replace): Replace a record, sending every field to keep

```json
{
  "onboarding_id": 4821,
  "first_name": "Alex",
  "last_name": "Morgan",
  "email": "alex.morgan@example.com",
  "mobile_no": "5125550148",
  "position_id": 14,
  "sub_position_id": 22,
  "office_id": 7,
  "start_date": "2026-11-09",
  "end_date": null,
  "recruiter_id": 57,
  "manager_id": 312,
  "lead_id": 1093,
  "team_id": null
}
```

## Example request

```bash
curl -X POST "https://marketplace-api.sequifi.com/v1/onboarding" \
  -H "Authorization: Bearer $SEQUIFI_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"first_name":"Alex","last_name":"Morgan","email":"alex.morgan@example.com","mobile_no":"5125550148","position_id":14,"sub_position_id":22,"office_id":7,"start_date":"2026-11-02","recruiter_id":57,"manager_id":312,"lead_id":1093}'
```

## Responses

### 200: Replaced (the body had `onboarding_id`). Pay was reset to the position's defaults.

- `status` (integer): Same as the HTTP status code. Example: `200`.
- `message` (string) Example: `success`.
- `data` (object)
  - `requested_by` (string): Label of the API credentials that made the call.
  - `onboarding_id` (integer): The record that was replaced.
  - `employee_id` (string): The record's onboarding id string (unchanged).
  - `commissions_added` (integer): Commission settings copied again from the position. The other counts work the same way as on create.

```json
{
  "status": 200,
  "message": "success",
  "data": {
    "requested_by": "acme",
    "onboarding_id": 4821,
    "employee_id": "ONB0012",
    "products_linked": 2,
    "commissions_added": 3,
    "upfronts_added": 1,
    "overrides_added": 2,
    "withheld_added": 0,
    "deductions_added": 1
  }
}
```

### 201: Created in Draft. Nothing was sent to the person.

- `status` (integer): Same as the HTTP status code. Example: `201`.
- `message` (string) Example: `success`.
- `data` (object)
  - `requested_by` (string): Label of the API credentials that made the call.
  - `onboarding_id` (integer): The new record's id. Use it for send-offer and hire.
  - `employee_id` (string): Onboarding id string, for example `ONB0012`.
  - `products_linked` (integer): Products on the position.
  - `commissions_added` (integer): Commission settings copied from the position.
  - `upfronts_added` (integer): Upfront settings copied.
  - `overrides_added` (integer): Override settings copied.
  - `withheld_added` (integer): Withholding settings copied.
  - `deductions_added` (integer): Deductions copied.

```json
{
  "status": 201,
  "message": "success",
  "data": {
    "requested_by": "acme",
    "onboarding_id": 4821,
    "employee_id": "ONB0012",
    "products_linked": 2,
    "commissions_added": 3,
    "upfronts_added": 1,
    "overrides_added": 2,
    "withheld_added": 0,
    "deductions_added": 1
  }
}
```

### 400: A field failed a check, the person already exists, or the position is not fully set up. The message says which.

Example (missing_fields): A required name or contact field is missing

```json
{
  "status": 400,
  "message": "first_name, last_name, email, mobile_no are required.",
  "data": {}
}
```

### 401: Missing, unknown, expired or disabled token. Sent by the gateway as `{"message":"Unauthorized"}`, without `status` or `data`.

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

### 404: Replace only. No onboarding record has this `onboarding_id`.

```json
{
  "status": 404,
  "message": "Onboarding record with id 4821 not found.",
  "data": {}
}
```

### 500: Unexpected server error, including a malformed `start_date` or `end_date`. Check for the record before retrying a create.

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

### 503: Busy assigning the next onboarding id. Nothing was created. Retry after a short wait.

```json
{
  "status": 503,
  "message": "Server is busy, please retry.",
  "data": {}
}
```
