# Bulk create milestones

Operation ID: `createMilestones`

Group: PSA › Milestones

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

`POST /psa/milestones`

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

Creates milestones on one or more PSA projects in one request. If any milestone can't be created, none are, and every broken rule is reported with its own error code. 'index' in an error's details is the milestone's position in the request.

The rules match the project's Milestones tab. A milestone is billable by default on a Billable project and can't be billable on an Internal or NonBillable one. A billable milestone needs an amount other than 0. A non-billable milestone is stored with amount 0 and no billing links. The amount is always in the project currency. Products and sales order links can't be set through this API. Every identifier you send or get back is a UUID.

The response lists the new milestones' ids in the order you sent them. Read one with GET psa/milestones/: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`: createMilestonesInput.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `milestones` | array<object> | yes | The milestones to create. If any of them can't be created, none are. Example: `[{"projectId":"2d9e4f71-0b38-4c6a-a5d2-71e8c3f90b46","name":"Phase 1 delivery","dueDate":"2026-09-30","amount":"15000.00"},{"projectId":"2d9e4f71-0b38-4c6a-a5d2-71e8c3f90b46","name":"Go-live","description":"Production cut-over and sign-off.","dueDate":"2026-12-15","status":"pending","billable":true,"amount":"25000.00"}]`. |
| `milestones[].projectId` | string | yes | The PSA project the milestone belongs to. You need edit rights on it. See id on GET psa/projects/:id. |
| `milestones[].name` | string | yes | The display name of the milestone. Can't be empty. |
| `milestones[].description` | string \| null | no | A free-form description of the milestone. |
| `milestones[].dueDate` | date | yes | The date the milestone is due. Must be within the project's start and end dates. Use format YYYY-MM-DD. |
| `milestones[].status` | string | no | The status of the milestone. Defaults to 'pending'. A milestone becomes 'invoiced' only through invoicing. One of: `"pending"`, `"accomplished"`. |
| `milestones[].billable` | boolean | no | Whether the milestone is billable to a customer. Defaults to true on a Billable project and false otherwise. Can't be true on an Internal or NonBillable project. |
| `milestones[].amount` | decimal \| null | no | The milestone amount, in the project currency. Required and other than 0 when the milestone is billable; not negative, at most 2 decimal places. Must be absent, null or 0 when it is not billable, and is then stored as 0. |
| `milestones[].salesOrderProductLineId` | string \| null | no | The sales order product line this milestone fulfills. It must be a one-time, milestone-billed line on a sales order of the project's sales arrangement that no other project uses. Only on a billable milestone. Send null to unlink. See id in the salesOrderProductLines collection (SalesOrderListProductLinesEndpointV1). |
| `milestones[].invoiceMilestoneId` | string \| null | no | The invoice milestone this milestone is linked to. It must be on salesOrderProductLineId, not yet invoiced, and not linked to another milestone of the project. While linked, it sets the milestone's name and, when it has a price, its amount. Send null to unlink. See invoiceMilestoneId on GET psa/milestones/:id. |

```json
{
  "milestones": [
    {
      "projectId": "2d9e4f71-0b38-4c6a-a5d2-71e8c3f90b46",
      "name": "Phase 1 delivery",
      "dueDate": "2026-09-30",
      "amount": "15000.00"
    },
    {
      "projectId": "2d9e4f71-0b38-4c6a-a5d2-71e8c3f90b46",
      "name": "Go-live",
      "description": "Production cut-over and sign-off.",
      "dueDate": "2026-12-15",
      "status": "pending",
      "billable": true,
      "amount": "25000.00"
    }
  ]
}
```

## Response

`200` Success

Under `data` (createMilestonesOutput):

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `created` | array<object> | yes | The created milestones, in the order the request sent them. Read a record with GET psa/milestones/:id for its stored state. Example: `[{"id":"9b1c7f42-3d8a-4e05-b6c1-27fa5e903d18"},{"id":"5e0a4c1b-8f27-4d63-a9b2-c14d7e66f031"}]`. |
| `created[].id` | string | yes | The unique identifier for the created milestone. |

```json
{
  "data": {
    "created": [
      {
        "id": "9b1c7f42-3d8a-4e05-b6c1-27fa5e903d18"
      },
      {
        "id": "5e0a4c1b-8f27-4d63-a9b2-c14d7e66f031"
      }
    ]
  },
  "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 |
| --- | --- |
| `PROJECT_NOT_FOUND` | 400 |
| `FORBIDDEN` | 400 |
| `NAME_REQUIRED` | 400 |
| `BILLABLE_NOT_ALLOWED` | 400 |
| `AMOUNT_REQUIRED` | 400 |
| `AMOUNT_NOT_ALLOWED` | 400 |
| `AMOUNT_NEGATIVE` | 400 |
| `AMOUNT_TOO_PRECISE` | 400 |
| `DUE_DATE_OUTSIDE_PROJECT` | 400 |
| `SALES_ORDER_LINK_NOT_ALLOWED` | 400 |
| `SALES_ORDER_PRODUCT_LINE_NOT_AVAILABLE` | 400 |
| `INVOICE_MILESTONE_NOT_AVAILABLE` | 400 |
| `IDEMPOTENCY_KEY_CONFLICT` | 409 |
| `IDEMPOTENCY_PAYLOAD_MISMATCH` | 422 |

## Statuses

- `400` — Invalid request or business failure. Codes: PROJECT_NOT_FOUND, FORBIDDEN, NAME_REQUIRED, BILLABLE_NOT_ALLOWED, AMOUNT_REQUIRED, AMOUNT_NOT_ALLOWED, AMOUNT_NEGATIVE, AMOUNT_TOO_PRECISE, DUE_DATE_OUTSIDE_PROJECT, SALES_ORDER_LINK_NOT_ALLOWED, SALES_ORDER_PRODUCT_LINE_NOT_AVAILABLE, INVOICE_MILESTONE_NOT_AVAILABLE
- `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
