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

# Record a time entry

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

Module: Timesheet · operationId: `addTimesheetEntry` · Auth: `Authorization: Bearer <token>`
Web page: https://apidocs.sequifi.com/#/api/add-timesheet-entry

Records time for a user: a whole finished entry (a `checkin` with `end_time` and pay), or a single clock event. For imports from a field tool, send each finished entry as one `checkin` call with `time`, `end_time`, a stable `external_reference_id` and its pay fields.

**Before you call:**

- Get the user id from GET /v1/users. Terminated and disabled users are rejected.
- Check that the user is set up for time: GET /v1/timesheet?user_id=...&pay_period=current should return `200`.
- Send times as local wall-clock time without a UTC offset, for example `2026-10-06T08:00:00` (see Formats).

**What happens:**

- `checkin` finds or creates the user's day for the date of `time`. If `external_reference_id` matches a clock-in already on that same day, it updates that clock-in (time, pay, job) and, when `end_time` is sent, its clock-out. Otherwise it adds a clock-in, plus a clock-out when `end_time` is sent. With `end_time`, the day's worked, lunch and break totals are recalculated.
- `approved: true` marks the day approved for payroll. It works only with `checkin` and cannot un-approve a day.
- `start_lunch` and `start_break` need a day that already has a clock-in. They record the start and leave the end open. `stop_lunch` and `stop_break` close it.
- `checkout` adds a clock-out every time (it never matches by reference id) and recalculates the day's totals.
- Pay is stored on the clock-in: `labor_rate` × `final_duration` / 3600, rounded to three decimals, or exactly `flat_amount` when sent (then no rate is stored). Pay follows `final_duration`, not the clock times, so send `final_duration` equal to the worked seconds.
- After a successful `checkin` or `checkout`, Sequifi recalculates the user's hourly pay on the open payroll. It normally shows within minutes; a scheduled catch-up runs every 30 minutes and nightly.

**Idempotency and retries:**

- A `checkin` re-sent with the same `external_reference_id` on the same day updates the entry instead of adding one. Without a reference id, every retry adds another entry. `checkout` retries always add another clock-out.
- A re-post replaces the pay: if it omits `labor_rate`, `final_duration` and `flat_amount`, the entry's pay is cleared. Always resend the whole entry.
- A re-post cannot add a missing clock-out. If the first post had no `end_time`, a later post with `end_time` and the same reference id updates the clock-in but adds no clock-out, and the entry's hours stay 0. Send `time` and `end_time` together in the first call.
- Matching is per day. If an entry moves to another date, the old one stays; there is no delete endpoint, so ask an admin to remove it.
- Send one request at a time per user and day. There is no locking, and parallel first posts for a day can create two day records.

**Formats:**

- `time`, `end_time` and `date` accept any date-time string. One with `Z` or an offset is converted to UTC before it is stored: `2026-10-06T18:30:00-06:00` is stored as `2026-10-07 00:30:00`, on the next day. A value without an offset is stored as sent.
- Response times are `YYYY-MM-DD HH:MM:SS` and totals are `HH:MM:SS`.
- `Total_earning` in the response is an estimate from the user's profile pay rate, not from the pay you sent, and the response totals cover only the day's last clock-in and clock-out. Read GET /v1/timesheet to check what was stored.

**Errors:**

- `400 Invalid JSON body`, `400 user_id is required`, `400 type is required`, `400 Invalid type` (with `data.allowed_types`).
- `400 flat_amount must be a number greater than or equal to 0`. An empty string is accepted as 0.
- `404 User not found`, `400 User is terminated and cannot perform this action`, `400 User account is disabled`: stop syncing that user.
- `400 Invalid time format` and `400 Invalid end_time format`. An invalid `end_time` is reported after the clock-in was already saved; fix the value and ask an admin to check the day, because a re-post cannot add the clock-out.
- `400 You not checked in today`: a break, lunch or `checkout` was sent for a day with no clock-in.
- `400 Priority end lunch` (or `end break`): a lunch or break is still open; close it first.
- `400 Missing Start time`: a stop was sent with no open lunch or break.
- Rule failures (the last three) return the same `data.timesheet` block as a success.
- A non-numeric `labor_rate` or `final_duration` returns `500`.

**Related:**

- GET /v1/timesheet reads back what was stored.
- GET /v1/payroll shows the resulting wages in `hourly_salary`.

## Request body

- `user_id` (integer, **required**): User id from GET /v1/users. Example: `4821`.
- `type` (string, **required**): The action. Case-sensitive. One of: `checkin`, `start_lunch`, `stop_lunch`, `start_break`, `stop_break`, `checkout`. Example: `checkin`.
- `time` (string (date-time)): When the action happened. Send local wall-clock time without an offset. Defaults to now (UTC). Example: `2026-10-06T08:00:00`.
- `date` (string (date-time)): Used only when `time` is not sent. Same rules as `time`. Example: `2026-10-06T08:00:00`.
- `end_time` (string (date-time)): With `checkin` only. Records the matching clock-out at this time. Send it in the first call for the entry. Example: `2026-10-06T12:00:00`.
- `external_reference_id` (string): Your id for this entry. With `checkin`, a re-post with the same id on the same day updates the entry instead of adding one. Example: `fieldtool:entry:10482`.
- `labor_rate` (number): Hourly rate in dollars. Ignored when `flat_amount` is sent. Example: `20`.
- `final_duration` (integer): Worked seconds, net of unpaid breaks. Pay is `labor_rate` × `final_duration` / 3600. Example: `14400`.
- `flat_amount` (number): Fixed pay in dollars for the entry, for example a fixed-price job. Replaces `labor_rate` × `final_duration`. Minimum: 0. Example: `85`.
- `job_id` (string): Job reference shown on the pay stub line. Example: `1042`.
- `job_name` (string): Job label shown on the pay stub line. Example: `Unit turn clean`.
- `approved` (boolean): With `checkin` only. `true` marks the day approved for payroll. Example: `true`.
- `office_id` (integer): Office id. Defaults to `0`. Example: `0`.

Example (finished_entry): A finished hourly entry from a field tool

```json
{
  "user_id": 4821,
  "type": "checkin",
  "time": "2026-10-06T08:00:00",
  "end_time": "2026-10-06T12:00:00",
  "external_reference_id": "fieldtool:entry:10482",
  "job_id": "1042",
  "job_name": "Unit turn clean",
  "labor_rate": 20,
  "final_duration": 14400,
  "approved": true
}
```

Example (flat_price_entry): A fixed-price job

```json
{
  "user_id": 4821,
  "type": "checkin",
  "time": "2026-10-07T09:00:00",
  "end_time": "2026-10-07T10:30:00",
  "external_reference_id": "fieldtool:entry:10483",
  "job_id": "1043",
  "job_name": "Carpet clean",
  "flat_amount": 85,
  "final_duration": 0,
  "approved": true
}
```

## Example request

```bash
curl -X POST "https://marketplace-api.sequifi.com/v1/timesheet" \
  -H "Authorization: Bearer $SEQUIFI_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"user_id":4821,"type":"checkin","time":"2026-10-06T08:00:00","end_time":"2026-10-06T12:00:00","external_reference_id":"fieldtool:entry:10482","job_id":"1042","job_name":"Unit turn clean","labor_rate":20,"final_duration":14400,"approved":true}'
```

## Responses

### 200: Action recorded

- `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): Label of the API credential that made the call.
  - `timesheet` (object): Summary of the user's day. Covers only the last clock-in and clock-out pair.
    - `checkin` (string): Latest clock-in, `YYYY-MM-DD HH:MM:SS`. Absent when there is none.
    - `checkout` (string): Latest clock-out, `YYYY-MM-DD HH:MM:SS`. Absent when there is none.
    - `current_state` (string): Where the day stands, for example `Notcheckin`, `checkin`, `lunch`, `break` or `checkout`.
    - `current_state_start_time` (string): When the current state started, `YYYY-MM-DD HH:MM:SS`, or an empty string.
    - `Total_hour` (string): Clock-in to clock-out time, `HH:MM:SS`.
    - `Total_hour_work` (string): That time minus lunch and breaks, `HH:MM:SS`.
    - `Total_lunch` (string): Lunch time, `HH:MM:SS`.
    - `Total_break` (string): Break time, `HH:MM:SS`.
    - `Total_earning` (number): Estimate from the user's profile pay rate. Not the pay stored for the entry.

Example (finished_entry): checkin with end_time

```json
{
  "status": 200,
  "message": "Check-in and check-out successful",
  "data": {
    "requestedBy": "acme",
    "timesheet": {
      "checkin": "2026-10-06 08:00:00",
      "checkout": "2026-10-06 12:00:00",
      "current_state": "checkout",
      "current_state_start_time": "2026-10-06 12:00:00",
      "Total_hour": "04:00:00",
      "Total_hour_work": "04:00:00",
      "Total_lunch": "00:00:00",
      "Total_break": "00:00:00",
      "Total_earning": 80
    }
  }
}
```

Example (updated_entry): Re-post of an existing entry

```json
{
  "status": 200,
  "message": "Timesheet entry updated",
  "data": {
    "requestedBy": "acme",
    "timesheet": {
      "checkin": "2026-10-06 08:00:00",
      "checkout": "2026-10-06 12:30:00",
      "current_state": "checkout",
      "current_state_start_time": "2026-10-06 12:30:00",
      "Total_hour": "04:30:00",
      "Total_hour_work": "04:30:00",
      "Total_lunch": "00:00:00",
      "Total_break": "00:00:00",
      "Total_earning": 90
    }
  }
}
```

### 400: Invalid request, or the action does not fit the user's day

Example (missing_user_id): user_id not sent

```json
{
  "status": 400,
  "message": "user_id is required",
  "data": {
    "required_fields": [
      "user_id",
      "type"
    ]
  }
}
```

### 401: Missing, invalid or expired token. The gateway rejects the call before it reaches Sequifi, so the body has only a `message`.

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

### 404: User not found

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

### 500: Internal server error, including a non-numeric labor_rate or final_duration

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