# Create a payroll detail

Operation ID: `createPayrollDetail`

Group: Accounting › Payroll Details

[Open in the interactive reference](https://docs.api.lensing.ai/lensing/v1/endpoints/createPayrollDetail)

`POST /accounting/payroll-details`

Retry-safe: A write that accepts Idempotency-Key: repeating a request with the same key replays the stored answer instead of executing twice.

Creates a payroll detail. The payroll detail belongs to one legal entity and takes its categories, journal entry date rule, and clearing account from the payroll template you name.

Gross pay must equal deductions plus net pay across all lines, or the request fails with AMOUNT_NOT_BALANCED.

The journal entry date comes from the template's journal entry date rule, either payrollDate or endDate. The legal entity must have a default transactions book (NO_ACCOUNTING_BOOK). A period in that book must cover the journal entry date (NO_ACCOUNTING_PERIOD), and that period must be open (POSTING_PERIOD_CLOSED).

The response contains only the new payroll detail's id. To see it, use GET accounting/payroll-details/:id.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Api-Version` | header | string · v1 | yes | The API version this request targets, named by its public identifier. Required on every request; omitting it, or naming a version this company does not have, is answered with 400. This document describes version `v1`. |
| `Idempotency-Key` | header | string | no | An opaque caller-chosen string (1-255 characters) that makes this request safe to retry. Repeating the same key with an identical request body replays the original response instead of re-executing - but only once that original request succeeded; a failed attempt re-executes on retry. Repeating the key with a different body is answered with 422. A key still in flight is answered with 409 - as is a key whose original request was interrupted before it finished, for a few minutes afterwards, until that attempt is presumed dead. A completed response stays replayable for 24 hours. The key is scoped to the caller, not to the action: reusing it for a different action is answered with 409 or 422 rather than treated independently. On read actions this header is ignored. On write actions that cannot offer the guarantee it is answered with `400 IDEMPOTENCY_NOT_SUPPORTED` rather than silently ignored. |

## Request body

Required, `application/json`: createPayrollDetailInput.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `templateId` | string | yes | The payroll template this run uses. See id on GET accounting/payroll-templates/:id. It supplies the categories, the journal-entry-date rule, the group-by and the clearing account. Example: `"b7e4c1a9-3f52-4d86-9017-5a2c8e0b4d61"`. |
| `entityId` | string | yes | The legal entity that owns the payroll. See id on GET base/entities. Example: `"7c1a9e40-2b53-4d68-9f01-3a5b7c9d1e24"`. |
| `grouping` | string | yes | How the payroll is grouped. Values include 'Employee', 'Department' and 'Multi-level'. Example: `"Employee"`. |
| `status` | string | no | The status of the payroll. Defaults to 'pendingApproval' when omitted. |
| `payrollDate` | date | yes | The issue date of the payroll. Use format YYYY-MM-DD. Example: `"2026-08-31"`. |
| `startDate` | date | no | The first day of the payroll period. Use format YYYY-MM-DD. Example: `"2026-08-01"`. |
| `endDate` | date | no | The last day of the payroll period, which must not be before the start date. Use format YYYY-MM-DD. Example: `"2026-08-31"`. |
| `currency` | string | yes | The currency the payroll is denominated in. Format ISO 4217, for example 'USD'. Example: `"USD"`. |
| `description` | string | no | A description of the payroll. Example: `"August 2026 payroll"`. |
| `isNetPayCategoryMapped` | boolean | no | Whether the net-pay category is matched in the account mapping. Defaults to false. |
| `origin` | string | no | The source system this record came from, as free-form text, for example 'Ramp'. Omit it and it stays unset. The server does not set a value. |
| `lines` | array<object> | yes | The payroll's lines, one per employee or department depending on the grouping. Example: `[{"employeeId":"3f1a8c25-9d47-4e60-b892-0c5a7e3b1d84","lineItems":[{"categoryId":"9b2d5e10-4c78-4a36-8f51-6e0a3c7b2d95","amount":"5000.00"},{"categoryId":"e5c7a390-1d64-4b28-9a07-2f8b6d4c1e53","amount":"5000.00"}]}]`. |
| `lines[].employeeId` | string | no | The employee this line is for. There is no endpoint for it. With grouping 'Employee', a line that names an employee but no department has the department backfilled from that employee's primary job. |
| `lines[].departmentId` | string | no | The department this line is charged to. See id on GET people/departments/:id. |
| `lines[].lineItems` | array<object> | yes | The amounts on this line, one per payroll category. Each category must be reachable from the payroll's template. An item whose amount is null is dropped before the payroll is saved. |
| `lines[].lineItems[].categoryId` | string | yes | The payroll category this amount belongs to. There is no endpoint for it. It must be an active category of the payroll's template. |
| `lines[].lineItems[].amount` | decimal | yes | The amount for this category, as a decimal in the payroll's currency. |
| `attachments` | array<object> | no | Files to attach to the payroll. Omit for none, unless your tenant requires an attachment, in which case omitting them fails with ATTACHMENT_REQUIRED. |
| `attachments[].fileName` | string | yes | The display name of the attached file. |
| `attachments[].fileId` | string | yes | The identifier of the uploaded file in file storage, as a text reference. There is no endpoint for it. |

```json
{
  "templateId": "b7e4c1a9-3f52-4d86-9017-5a2c8e0b4d61",
  "entityId": "7c1a9e40-2b53-4d68-9f01-3a5b7c9d1e24",
  "grouping": "Employee",
  "status": "<status>",
  "payrollDate": "2026-08-31",
  "startDate": "2026-08-01",
  "endDate": "2026-08-31",
  "currency": "USD",
  "description": "August 2026 payroll",
  "isNetPayCategoryMapped": true,
  "origin": "<origin>",
  "lines": [
    {
      "employeeId": "3f1a8c25-9d47-4e60-b892-0c5a7e3b1d84",
      "lineItems": [
        {
          "categoryId": "9b2d5e10-4c78-4a36-8f51-6e0a3c7b2d95",
          "amount": "5000.00"
        },
        {
          "categoryId": "e5c7a390-1d64-4b28-9a07-2f8b6d4c1e53",
          "amount": "5000.00"
        }
      ]
    }
  ],
  "attachments": [
    {
      "fileName": "<fileName>",
      "fileId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
    }
  ]
}
```

## Response

`200` Success

Under `data` (createPayrollDetailOutput):

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes | The unique identifier for the created payroll run. Example: `"4d8f2b61-7a09-4c35-8e12-9b3d5f0a6c47"`. |

```json
{
  "data": {
    "id": "4d8f2b61-7a09-4c35-8e12-9b3d5f0a6c47"
  },
  "diagnostics": [
    {
      "code": "<code>",
      "message": "<message>",
      "severity": "error",
      "path": [
        "<path>"
      ],
      "details": "<details>"
    }
  ]
}
```

## Response headers

- `Idempotency-Replayed` — Present and `true` only when this response replays a previously stored one for the same Idempotency-Key, rather than reflecting a live execution. Absent on a live response - never sent as `false`.

## Errors

| Code | Status |
| --- | --- |
| `REFERENCE_NOT_FOUND` | 400 |
| `CATEGORY_NOT_IN_TEMPLATE` | 400 |
| `INVALID_DATE_RANGE` | 400 |
| `AMOUNT_NOT_BALANCED` | 400 |
| `NO_ACCOUNTING_BOOK` | 400 |
| `NO_ACCOUNTING_PERIOD` | 400 |
| `POSTING_PERIOD_CLOSED` | 400 |
| `TOO_MANY_LINES` | 400 |
| `ATTACHMENT_REQUIRED` | 400 |
| `IDEMPOTENCY_KEY_CONFLICT` | 409 |
| `IDEMPOTENCY_PAYLOAD_MISMATCH` | 422 |

## Statuses

- `400` — Invalid request or business failure. Codes: REFERENCE_NOT_FOUND, CATEGORY_NOT_IN_TEMPLATE, INVALID_DATE_RANGE, AMOUNT_NOT_BALANCED, NO_ACCOUNTING_BOOK, NO_ACCOUNTING_PERIOD, POSTING_PERIOD_CLOSED, TOO_MANY_LINES, ATTACHMENT_REQUIRED
- `401` — The request carries no valid access token.
- `403` — Not authorized
- `404` — Not found
- `409` — The Idempotency-Key is still being processed by another request.
- `422` — The Idempotency-Key was already used with a different request payload.
- `429` — Too many requests from this client address. The response has no body and no `Retry-After` header.
- `500` — Internal server error
