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

# Send an offer letter

`POST https://marketplace-api.sequifi.com/v1/onboarding/{id}/send-offer`

Module: Onboarding · operationId: `sendOfferLetter` · Auth: `Authorization: Bearer <token>`
Web page: https://apidocs.sequifi.com/#/api/send-offer-letter

Emails the candidate their offer letter for a Draft onboarding record, the same way **Send offer letter** works in the Sequifi app. The letter template comes from the record's sub-position, which equals `position_id` when none was sent at create, so that position needs an offer letter template. A `200` means the send ran, not that the email arrived: read `data.outcome`, and validate email addresses before you create the record.

**Before you call:**

- The record must be in Draft (`status_id` 8), which is how `POST /v1/onboarding` creates it.
- Your company must have SequiDocs turned on.
- An offer letter template must be assigned to the record's sub-position and marked ready. API-created records always have a sub-position: when you did not send `sub_position_id`, it equals `position_id`, which is often a parent position with no template. Send the real `sub_position_id` at create time.
- The candidate's email domain must be allowed by your company's email settings.
- The offer is sent as the record's recruiter, else its manager, else the first active company admin, and that name is printed on the letter. Set `recruiter_id` at create time if the signature matters.

**What happens:**

The call waits for the send to finish (up to 25 seconds).

- If your company requires approval of offers, the record moves to `status_id` 17 (Offer Review) and nothing is emailed. `outcome` is `queued_for_review`. An admin approves it in the app.
- Otherwise the offer letter is generated as an e-sign document, with any documents attached to the template, and emailed to the candidate's personal `email` (not a work email) with a signing link. The record moves to `status_id` 4 (Offer Sent, Unread). `outcome` is `sent`.
- If the record is flagged for a background check and your company has S-Clearance, a background-check email is sent too.
- After that, the status changes as the candidate acts: 21 opened, 13, 22 or 23 accepted, 16 document review, 6 change requested, 2 declined, 5 expired. Poll `GET /v1/onboarding/{id}`.

**Idempotency and retries:**

- Safe to retry. Only a Draft record can be sent, so a repeat returns `409 NOT_SENDABLE` with the current `status_id`. Treat that as "already sent or waiting for review". It also fires when someone sent the offer in the app.
- A failed send leaves the record in Draft, so you can fix the cause and call again.
- On `502` or `504`, wait, retry once, and read the code. `409 NOT_SENDABLE` means the first call worked.
- Sends are limited to about 120 a minute for your company, and repeats count too.

**Formats:**

- The body is optional. Send `{}` or `{"template_id": 87}`. Other keys are ignored.
- `data.outcome` is `sent` or `queued_for_review`. `data.status_id` is 4 or 17.
- `data.template_id` is the template used. `data.sent_by_user_id` is the user the offer was sent as.
- Errors from the send carry `data.code` and `data.requestedBy`, and `409`/`422` errors also carry `data.onboarding_id`, `data.status_id` and `data.status_name`. Branch on `data.code`, not on `message`.

**Errors:**

- `400 Invalid onboarding id`, `400 Invalid JSON body`, `400 template_id must be a positive integer`
- `404 No onboarding record with id <n>.` (`NOT_FOUND`)
- `409` `ADDON_DISABLED`: SequiDocs is off for your company. `409` `NOT_SENDABLE`: the record is not in Draft.
- `422` `TEMPLATE_NOT_MAPPED`: no offer letter template is assigned to the sub-position (or `template_id` is not one of them). `TEMPLATE_NOT_READY`: the template is not marked ready. `NO_SENDER`: no recruiter, manager or active admin to send as. Your company admin fixes these in the app.
- `422` `SEND_FAILED`: the send stopped with a reason in `message`, for example `Domain setting isn't allowed to send email on this domain!!` (the candidate's email domain is not allowed) or `Offer Expiry Date should be in the future`. The record stays in Draft.
- `500 The offer letter could not be sent.` (`SEND_FAILED`), or `500 Could not resolve the tenant host`. The record stays in Draft.
- `502 Could not reach the tenant` or `502 The tenant returned an unreadable response`. The second most likely also covers going over about 120 sends a minute and unexpected errors. No `Retry-After` header is sent. Wait, then retry once.
- `503`: your company is not set up for offer sending over the API. Contact Sequifi support.
- `504`: no answer in time. The offer may have been sent. Retry once and read the code.

**Common mistakes:**

- Reading `200` as "the candidate has the offer". A mistyped email address is still reported as `sent`.
- Leaving out `sub_position_id` on create, then getting `TEMPLATE_NOT_MAPPED` here.
- Expecting the candidate to get login access from this email. It carries a signing link only.
- Hiring before the candidate accepts. `PUT /v1/onboarding/hire` does not check.

**Related:**

- `POST /v1/onboarding` creates the Draft record.
- `GET /v1/onboarding/{id}` to follow the status.
- `PUT /v1/onboarding/hire` once the offer is accepted.

## Path parameters

- `id` (integer, **required**): The `onboarding_id` returned by `POST /v1/onboarding`. Not a user id; no user exists until hire. Minimum: 1. Example: `4821`.

## Request body

- `template_id` (integer): Optional. Which offer letter template to use when the sub-position has more than one. Must be a template assigned to the record's sub-position as an offer letter. Leave it out to use the assigned template. Example: `87`.

Example (default_template): Use the template assigned to the sub-position

```json
{}
```

Example (chosen_template): Choose one of the sub-position's templates

```json
{
  "template_id": 87
}
```

## Example request

```bash
curl -X POST "https://marketplace-api.sequifi.com/v1/onboarding/4821/send-offer" \
  -H "Authorization: Bearer $SEQUIFI_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'
```

## Responses

### 200: The send ran. Read `data.outcome`; `sent` does not prove the email was delivered.

- `status` (integer): Same as the HTTP status code. Example: `200`.
- `message` (string): `Offer letter sent.` or `Offer letter queued for internal review.` Example: `Offer letter sent.`.
- `data` (object)
  - `requestedBy` (string): Label of the API credentials that made the call.
  - `onboarding_id` (integer): The onboarding id.
  - `employee_id` (string): Onboarding id string, for example `ONB0012`.
  - `outcome` (string): `sent`: emailed to the candidate (delivery not confirmed). `queued_for_review`: waiting for an admin; nothing emailed yet. One of: `sent`, `queued_for_review`.
  - `status_id` (integer): `4` (Offer Sent, Unread) or `17` (Offer Review).
  - `status_name` (string): Current status name.
  - `template_id` (integer, nullable): The offer letter template used.
  - `sent_by_user_id` (integer): The user the offer was sent as (recruiter, manager or company admin).

Example (sent): Offer emailed to the candidate

```json
{
  "status": 200,
  "message": "Offer letter sent.",
  "data": {
    "requestedBy": "acme",
    "onboarding_id": 4821,
    "employee_id": "ONB0012",
    "outcome": "sent",
    "status_id": 4,
    "status_name": "Offer Sent, Unread",
    "template_id": 87,
    "sent_by_user_id": 57
  }
}
```

Example (queued_for_review): Your company requires approval; nothing emailed yet

```json
{
  "status": 200,
  "message": "Offer letter queued for internal review.",
  "data": {
    "requestedBy": "acme",
    "onboarding_id": 4821,
    "employee_id": "ONB0012",
    "outcome": "queued_for_review",
    "status_id": 17,
    "status_name": "Offer Review",
    "template_id": 87,
    "sent_by_user_id": 57
  }
}
```

### 400: The path id or the body is invalid.

Example (invalid_id): Path id is not a positive whole number

```json
{
  "status": 400,
  "message": "Invalid onboarding id",
  "data": {}
}
```

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

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

### 404: No onboarding record has this id.

```json
{
  "status": 404,
  "message": "No onboarding record with id 4821.",
  "data": {
    "requestedBy": "acme",
    "code": "NOT_FOUND"
  }
}
```

### 409: The record is not in Draft (`NOT_SENDABLE`, also the answer to a retry of a call that worked), or SequiDocs is off for your company (`ADDON_DISABLED`).

Example (not_sendable): Already sent or waiting for review

```json
{
  "status": 409,
  "message": "This record is no longer in Draft, so an offer has already been sent or is awaiting review. Current status: Offer Sent, Unread.",
  "data": {
    "requestedBy": "acme",
    "code": "NOT_SENDABLE",
    "onboarding_id": 4821,
    "status_id": 4,
    "status_name": "Offer Sent, Unread"
  }
}
```

### 422: A setup requirement is not met, or the send stopped. Branch on `data.code`. The record stays in Draft.

Example (template_not_mapped): No offer letter template assigned to the sub-position

```json
{
  "status": 422,
  "message": "No offer letter template is mapped to sub-position \"Setter\" (id 14). An administrator must assign an offer letter template to that position before an offer can be sent.",
  "data": {
    "requestedBy": "acme",
    "code": "TEMPLATE_NOT_MAPPED",
    "onboarding_id": 4821,
    "status_id": 8,
    "status_name": "Draft"
  }
}
```

### 429: Rate limited at the gateway. The body is `{"message":"Too Many Requests"}`. Going over your company's limit of about 120 sends a minute most likely shows up as `502` instead. Wait and retry.

```json
{
  "message": "Too Many Requests"
}
```

### 500: The send failed unexpectedly (`SEND_FAILED`), or the company's Sequifi address could not be resolved. The record stays in Draft.

```json
{
  "status": 500,
  "message": "The offer letter could not be sent.",
  "data": {
    "requestedBy": "acme",
    "code": "SEND_FAILED",
    "onboarding_id": 4821,
    "status_id": 8,
    "status_name": "Draft"
  }
}
```

### 502: Your company's Sequifi app could not be reached, or sent a response the API could not read. The second case most likely also covers its rate limit and unexpected errors. Wait, retry once, and read the code.

Example (unreachable): Could not connect

```json
{
  "status": 502,
  "message": "Could not reach the tenant",
  "data": {
    "onboarding_id": 4821
  }
}
```

### 503: Your company is not set up for offer sending over the API. Contact Sequifi support.

```json
{
  "status": 503,
  "message": "This tenant is not configured for offer letter sending. Contact Sequifi support.",
  "data": {}
}
```

### 504: No answer in time. The offer may still have been sent. Retry once; `409 NOT_SENDABLE` means it was.

```json
{
  "status": 504,
  "message": "The tenant did not respond in time. The offer may still have been sent — retry this call: it returns 409 NOT_SENDABLE if the offer already went out.",
  "data": {
    "onboarding_id": 4821
  }
}
```
