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

# Save QuickBooks journal entry IDs

`PATCH https://marketplace-api.sequifi.com/v1/payroll-history`

Module: Payroll · operationId: `updatePaidPayrollJournalIds` · Auth: `Authorization: Bearer <token>`
Web page: https://apidocs.sequifi.com/#/api/update-paid-payroll-journal-ids

Saves a QuickBooks journal entry id on paid pay stubs, so they drop out of GET /v1/payroll-history?quickbooks_synced=false. Send a JSON array of 1 to 500 items keyed by `payroll_id`. A different id sent for a stub that already has one replaces it without warning.

**Before you call:**

- Take stubs from GET /v1/payroll-history?quickbooks_synced=false and create their journal entries in QuickBooks first.
- Use `payroll_id` from that list, not `id`.

**What happens:**

- All items are saved in one transaction: either every item is applied or none is.
- The id is saved on every paid record with that `payroll_id`, including records the GET list hides because their payment is in flight or failed.
- Any existing journal entry id is overwritten.
- A `payroll_id` with no paid record is listed in `data.not_found`. This is not an error.
- `data.updated` counts items, not records. An item sent twice counts twice.

**Idempotency and retries:**

- Sending the same id again is safe and changes nothing.
- Sending a new id replaces the old one, which leaves the earlier journal entry orphaned in QuickBooks. Check that `quickbooks_journal_entry_id` is null before you create an entry.
- After a batch, query GET /v1/payroll-history?quickbooks_synced=false again from page 1.

**Formats:**

- `payroll_id` must be a JSON integer. A string such as `"42"` is rejected.
- `quickbooks_journal_entry_id` must be a non-blank string. Leading and trailing spaces are trimmed.

**Errors:**

- `400 Request body must be a non-empty array of { payroll_id, quickbooks_journal_entry_id }`: the body is not a JSON array, is empty, or is not valid JSON.
- `400 Batch size exceeds 500 items — split into multiple requests`.
- `400 Validation failed`: `data.errors` lists each bad item by index, for example `"[0]: payroll_id must be a positive integer"`. Nothing is saved.

**Related:**

- GET /v1/payroll-history lists paid stubs and their `quickbooks_journal_entry_id`.

## Request body

- `payroll_id` (integer, **required**): The stub's `payroll_id` from GET /v1/payroll-history. Must be a JSON integer. Minimum: 1. Example: `5521`.
- `quickbooks_journal_entry_id` (string, **required**): Journal entry id returned by QuickBooks. Example: `JE-1042`.

Example

```json
[
  {
    "payroll_id": 5521,
    "quickbooks_journal_entry_id": "JE-1042"
  },
  {
    "payroll_id": 5522,
    "quickbooks_journal_entry_id": "JE-1043"
  }
]
```

## Example request

```bash
curl -X PATCH "https://marketplace-api.sequifi.com/v1/payroll-history" \
  -H "Authorization: Bearer $SEQUIFI_TOKEN" \
  -H "Content-Type: application/json" \
  -d '[{"payroll_id":5521,"quickbooks_journal_entry_id":"JE-1042"},{"payroll_id":5522,"quickbooks_journal_entry_id":"JE-1043"}]'
```

## Responses

### 200: Batch saved. Check `not_found` for ids with no paid record.

- `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.
  - `updated` (integer): Number of items that matched a paid record.
  - `not_found` (array of integer): `payroll_id` values with no paid record.

```json
{
  "status": 200,
  "message": "quickbooks_journal_entry_id saved",
  "data": {
    "requestedBy": "acme",
    "updated": 2,
    "not_found": []
  }
}
```

### 400: Invalid request body

Example (not_array): Body is not a non-empty array

```json
{
  "status": 400,
  "message": "Request body must be a non-empty array of { payroll_id, quickbooks_journal_entry_id }",
  "data": {}
}
```

### 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"
}
```

### 500: Internal server error. Nothing in the batch was saved.

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