> For the complete documentation index, see [llms.txt](https://www.boxhero.io/docs/llms.txt). Every page is available as Markdown by appending `.md` to its URL; this page is [Markdown](https://www.boxhero.io/docs/th/developers/api/reference/purchase-orders/update-purchase-order.md).

# Update a purchase order

> Partially updates a purchase order.

Omitted scalar fields are preserved; when `items` is provided it replaces the full line list.

`PUT https://rest.boxhero-app.com/v1/purchase-orders/{order_id}`

## การยืนยันสิทธิ์

- `Authorization` (string, จำเป็น): เฮดเดอร์การยืนยันตัวตนแบบ Bearer ในรูปแบบ `Bearer <token>` โดย `<token>` คือ [โทเค็น API](https://www.boxhero.io/docs/th/developers/api/authentication.md) ของคุณ

## พารามิเตอร์ของพาธ

- `order_id` (integer, minimum 0, maximum 2147483647, จำเป็น)

## เนื้อหาคำขอ

- `order_number` (string): Order number. Whitespace is ignored and letters are uppercased. Use only letters, numbers, hyphens, and underscores. Auto-generated when omitted on create.
- `partner_id` (integer, minimum 0, maximum 2147483647, nullable): Supplier for purchase orders or customer for sales orders. Pass null to clear.
- `order_time` (string | number | string): ISO 8601 timestamp or millisecond epoch.
- `estimated_time` (string | number | string, nullable): ISO 8601 timestamp or millisecond epoch.
- `memo` (string, max length 2000)
- `custom_fields` (array of object): Ordered custom field name-value pairs.

  - `name` (string, จำเป็น)
  - `value` (string, จำเป็น)
- `currency_code` (string, min length 3, max length 3): ISO 4217 currency code. On create, defaults to the team's currency when omitted. On update, omitting it keeps the stored value; it cannot be cleared.
- `items` (array of object): Replacement order lines. Omit to preserve the current lines. Within a line, include id to update an existing line in place, or omit it to add a new line.

  - `id` (integer, minimum 0, maximum 2147483647): Existing line id to update in place. Omit to add a new line.
  - `item_id` (integer, minimum 0, maximum 2147483647): Existing item id. Mutually exclusive with item_sku, bundle_id, bundle_sku.
  - `item_sku` (string, min length 1, max length 255): Item SKU (case-insensitive). Mutually exclusive with item_id, bundle_id, bundle_sku.
  - `bundle_id` (integer, minimum 0, maximum 2147483647): Existing bundle id. Mutually exclusive with item_id, item_sku, bundle_sku.
  - `bundle_sku` (string, min length 1, max length 255): Bundle SKU (case-sensitive). Mutually exclusive with item_id, item_sku, bundle_id.
  - `quantity` (number, จำเป็น): Quantity. May include up to four decimal places in core data.
  - `price` (string, จำเป็น)
  - `tax` (LineTaxInput, nullable): Tax configuration for an order or return line.

    - `name` (string, min length 1, max length 255, จำเป็น)
    - `rate` (string, จำเป็น): Decimal value encoded as a string to avoid floating point drift.
    - `inclusive` (boolean, จำเป็น)
  - `discount` (LineDiscountInput, nullable): Discount configuration for an order or return line.

    - `name` (string, min length 1, max length 255, จำเป็น)
    - `type` (string, จำเป็น): Discount type. `"percent"` is a 0-100 percentage; `"amount"` is an absolute amount.

      ค่าที่เป็นไปได้: `percent`, `amount`
    - `value` (string, จำเป็น): Decimal value encoded as a string to avoid floating point drift.
- `costs` (array of OrderCostInput): Replacement additional costs, in display order. Omit to preserve the current costs; pass an empty array to remove all of them.

  - `name` (string, min length 1, max length 255, จำเป็น): Cost name.
  - `amount` (string, จำเป็น): Cost amount. Negative for a deduction such as a prepayment. Additional costs carry no tax or discount, so the amount is the final value.
- `revision` (integer, minimum 0, maximum 9007199254740991): Latest observed revision. Omit to use the current revision.

## การตอบกลับ

**200** The updated purchase order's id.

- `id` (integer, minimum 0, maximum 2147483647, จำเป็น): Updated order id.

**400** Request validation failed (including an unknown `item_sku`/`bundle_sku`), core rejected the update, or the team is not in LOCATION mode.

- `id` (string, จำเป็น): Unique exception id (`ex_` followed by 32 lowercase hex chars, no dashes — e.g. `ex_8f5c0c8e0e0a4a3c9b3f4f2c4f6c8d2a`). Quote this in support tickets so we can find the request in our logs.
- `type` (string, จำเป็น): Stable, machine-readable error code (RFC 7807-style URI fragment). Branch your error handling on this, not on `title`.

  ค่าที่เป็นไปได้: `/errors/not-found`, `/errors/invalid-request`, `/errors/invalid-team-mode`, `/errors/tokens/invalid`, `/errors/tokens/required`, `/errors/too-many-requests`, `/errors/core/usage-limit-exceeded`, `/errors/core/forbidden`, `/errors/core/unhandled`, `/errors/unhandled`
- `title` (string, จำเป็น): Human-readable summary of the error, in English.
- `correlationID` (string, จำเป็น): Request correlation id (`rq_` followed by 32 lowercase hex chars, no dashes — e.g. `rq_01abf3...`). Identical to the `X-Correlation-Id` response header. A client-supplied `X-Correlation-Id` request header (at most 128 chars of `A-Z a-z 0-9 . _ : / = -`) is echoed back here and in the response header; a missing or invalid value is silently replaced with a generated `rq_…` id.
- `instance` (string): Pointer to the specific failing resource (e.g. `/items/12345`). Path-only, no `/v1` version prefix. Absent on unknown-path `404` and unexpected `500` responses.
- `code` (string): Sub-reason code surfaced from upstream BoxHero core (on core-mapped 4xx) or from the gateway itself (e.g. `not-available-for-api-token` on 403). Use this for fine-grained branching after dispatching on `type`.
- `errors` (array of object): Field-level error details. Present on request-validation `/errors/invalid-request` (400) responses. Absent on malformed-JSON `400`, `413` body-too-large, and most errors mapped from BoxHero core (which include it only when core supplies an array; this can include `403`). Each entry locates a single failure via JSONPath-like `path` segments and a human-readable `message`.

  - `path` (array of string | number, จำเป็น)
  - `message` (string, จำเป็น)

**401** Missing, invalid, or revoked API token. `/errors/tokens/required` when no Bearer token is sent; `/errors/tokens/invalid` when the token is unknown or revoked (a revoked token may keep working for up to 60 seconds because validation results are cached).

- `id` (string, จำเป็น): Unique exception id (`ex_` followed by 32 lowercase hex chars, no dashes — e.g. `ex_8f5c0c8e0e0a4a3c9b3f4f2c4f6c8d2a`). Quote this in support tickets so we can find the request in our logs.
- `type` (string, จำเป็น): Stable, machine-readable error code (RFC 7807-style URI fragment). Branch your error handling on this, not on `title`.

  ค่าที่เป็นไปได้: `/errors/not-found`, `/errors/invalid-request`, `/errors/invalid-team-mode`, `/errors/tokens/invalid`, `/errors/tokens/required`, `/errors/too-many-requests`, `/errors/core/usage-limit-exceeded`, `/errors/core/forbidden`, `/errors/core/unhandled`, `/errors/unhandled`
- `title` (string, จำเป็น): Human-readable summary of the error, in English.
- `correlationID` (string, จำเป็น): Request correlation id (`rq_` followed by 32 lowercase hex chars, no dashes — e.g. `rq_01abf3...`). Identical to the `X-Correlation-Id` response header. A client-supplied `X-Correlation-Id` request header (at most 128 chars of `A-Z a-z 0-9 . _ : / = -`) is echoed back here and in the response header; a missing or invalid value is silently replaced with a generated `rq_…` id.
- `instance` (string): Pointer to the specific failing resource (e.g. `/items/12345`). Path-only, no `/v1` version prefix. Absent on unknown-path `404` and unexpected `500` responses.
- `code` (string): Sub-reason code surfaced from upstream BoxHero core (on core-mapped 4xx) or from the gateway itself (e.g. `not-available-for-api-token` on 403). Use this for fine-grained branching after dispatching on `type`.
- `errors` (array of object): Field-level error details. Present on request-validation `/errors/invalid-request` (400) responses. Absent on malformed-JSON `400`, `413` body-too-large, and most errors mapped from BoxHero core (which include it only when core supplies an array; this can include `403`). Each entry locates a single failure via JSONPath-like `path` segments and a human-readable `message`.

  - `path` (array of string | number, จำเป็น)
  - `message` (string, จำเป็น)

**404** No purchase order with the given id was found in this team.

- `id` (string, จำเป็น): Unique exception id (`ex_` followed by 32 lowercase hex chars, no dashes — e.g. `ex_8f5c0c8e0e0a4a3c9b3f4f2c4f6c8d2a`). Quote this in support tickets so we can find the request in our logs.
- `type` (string, จำเป็น): Stable, machine-readable error code (RFC 7807-style URI fragment). Branch your error handling on this, not on `title`.

  ค่าที่เป็นไปได้: `/errors/not-found`, `/errors/invalid-request`, `/errors/invalid-team-mode`, `/errors/tokens/invalid`, `/errors/tokens/required`, `/errors/too-many-requests`, `/errors/core/usage-limit-exceeded`, `/errors/core/forbidden`, `/errors/core/unhandled`, `/errors/unhandled`
- `title` (string, จำเป็น): Human-readable summary of the error, in English.
- `correlationID` (string, จำเป็น): Request correlation id (`rq_` followed by 32 lowercase hex chars, no dashes — e.g. `rq_01abf3...`). Identical to the `X-Correlation-Id` response header. A client-supplied `X-Correlation-Id` request header (at most 128 chars of `A-Z a-z 0-9 . _ : / = -`) is echoed back here and in the response header; a missing or invalid value is silently replaced with a generated `rq_…` id.
- `instance` (string): Pointer to the specific failing resource (e.g. `/items/12345`). Path-only, no `/v1` version prefix. Absent on unknown-path `404` and unexpected `500` responses.
- `code` (string): Sub-reason code surfaced from upstream BoxHero core (on core-mapped 4xx) or from the gateway itself (e.g. `not-available-for-api-token` on 403). Use this for fine-grained branching after dispatching on `type`.
- `errors` (array of object): Field-level error details. Present on request-validation `/errors/invalid-request` (400) responses. Absent on malformed-JSON `400`, `413` body-too-large, and most errors mapped from BoxHero core (which include it only when core supplies an array; this can include `403`). Each entry locates a single failure via JSONPath-like `path` segments and a human-readable `message`.

  - `path` (array of string | number, จำเป็น)
  - `message` (string, จำเป็น)

**409** The supplied revision is stale.

- `id` (string, จำเป็น): Unique exception id (`ex_` followed by 32 lowercase hex chars, no dashes — e.g. `ex_8f5c0c8e0e0a4a3c9b3f4f2c4f6c8d2a`). Quote this in support tickets so we can find the request in our logs.
- `type` (string, จำเป็น): Stable, machine-readable error code (RFC 7807-style URI fragment). Branch your error handling on this, not on `title`.

  ค่าที่เป็นไปได้: `/errors/not-found`, `/errors/invalid-request`, `/errors/invalid-team-mode`, `/errors/tokens/invalid`, `/errors/tokens/required`, `/errors/too-many-requests`, `/errors/core/usage-limit-exceeded`, `/errors/core/forbidden`, `/errors/core/unhandled`, `/errors/unhandled`
- `title` (string, จำเป็น): Human-readable summary of the error, in English.
- `correlationID` (string, จำเป็น): Request correlation id (`rq_` followed by 32 lowercase hex chars, no dashes — e.g. `rq_01abf3...`). Identical to the `X-Correlation-Id` response header. A client-supplied `X-Correlation-Id` request header (at most 128 chars of `A-Z a-z 0-9 . _ : / = -`) is echoed back here and in the response header; a missing or invalid value is silently replaced with a generated `rq_…` id.
- `instance` (string): Pointer to the specific failing resource (e.g. `/items/12345`). Path-only, no `/v1` version prefix. Absent on unknown-path `404` and unexpected `500` responses.
- `code` (string): Sub-reason code surfaced from upstream BoxHero core (on core-mapped 4xx) or from the gateway itself (e.g. `not-available-for-api-token` on 403). Use this for fine-grained branching after dispatching on `type`.
- `errors` (array of object): Field-level error details. Present on request-validation `/errors/invalid-request` (400) responses. Absent on malformed-JSON `400`, `413` body-too-large, and most errors mapped from BoxHero core (which include it only when core supplies an array; this can include `403`). Each entry locates a single failure via JSONPath-like `path` segments and a human-readable `message`.

  - `path` (array of string | number, จำเป็น)
  - `message` (string, จำเป็น)

**413** Request body exceeds the size limit (1 MiB). Returned with type `/errors/invalid-request`.

- `id` (string, จำเป็น): Unique exception id (`ex_` followed by 32 lowercase hex chars, no dashes — e.g. `ex_8f5c0c8e0e0a4a3c9b3f4f2c4f6c8d2a`). Quote this in support tickets so we can find the request in our logs.
- `type` (string, จำเป็น): Stable, machine-readable error code (RFC 7807-style URI fragment). Branch your error handling on this, not on `title`.

  ค่าที่เป็นไปได้: `/errors/not-found`, `/errors/invalid-request`, `/errors/invalid-team-mode`, `/errors/tokens/invalid`, `/errors/tokens/required`, `/errors/too-many-requests`, `/errors/core/usage-limit-exceeded`, `/errors/core/forbidden`, `/errors/core/unhandled`, `/errors/unhandled`
- `title` (string, จำเป็น): Human-readable summary of the error, in English.
- `correlationID` (string, จำเป็น): Request correlation id (`rq_` followed by 32 lowercase hex chars, no dashes — e.g. `rq_01abf3...`). Identical to the `X-Correlation-Id` response header. A client-supplied `X-Correlation-Id` request header (at most 128 chars of `A-Z a-z 0-9 . _ : / = -`) is echoed back here and in the response header; a missing or invalid value is silently replaced with a generated `rq_…` id.
- `instance` (string): Pointer to the specific failing resource (e.g. `/items/12345`). Path-only, no `/v1` version prefix. Absent on unknown-path `404` and unexpected `500` responses.
- `code` (string): Sub-reason code surfaced from upstream BoxHero core (on core-mapped 4xx) or from the gateway itself (e.g. `not-available-for-api-token` on 403). Use this for fine-grained branching after dispatching on `type`.
- `errors` (array of object): Field-level error details. Present on request-validation `/errors/invalid-request` (400) responses. Absent on malformed-JSON `400`, `413` body-too-large, and most errors mapped from BoxHero core (which include it only when core supplies an array; this can include `403`). Each entry locates a single failure via JSONPath-like `path` segments and a human-readable `message`.

  - `path` (array of string | number, จำเป็น)
  - `message` (string, จำเป็น)

**429** Rate limit exceeded. Limits are per team and shared by all of the team's API tokens: 5 requests per second and 300 requests per minute. The `RateLimit` and `X-RateLimit-*` headers reflect the per-minute window; check them and `Retry-After` before retrying. This status is also returned when the client IP exceeds 30 failed authentication attempts within 60 seconds, even if the token is valid.

- `id` (string, จำเป็น): Unique exception id (`ex_` followed by 32 lowercase hex chars, no dashes — e.g. `ex_8f5c0c8e0e0a4a3c9b3f4f2c4f6c8d2a`). Quote this in support tickets so we can find the request in our logs.
- `type` (string, จำเป็น): Stable, machine-readable error code (RFC 7807-style URI fragment). Branch your error handling on this, not on `title`.

  ค่าที่เป็นไปได้: `/errors/not-found`, `/errors/invalid-request`, `/errors/invalid-team-mode`, `/errors/tokens/invalid`, `/errors/tokens/required`, `/errors/too-many-requests`, `/errors/core/usage-limit-exceeded`, `/errors/core/forbidden`, `/errors/core/unhandled`, `/errors/unhandled`
- `title` (string, จำเป็น): Human-readable summary of the error, in English.
- `correlationID` (string, จำเป็น): Request correlation id (`rq_` followed by 32 lowercase hex chars, no dashes — e.g. `rq_01abf3...`). Identical to the `X-Correlation-Id` response header. A client-supplied `X-Correlation-Id` request header (at most 128 chars of `A-Z a-z 0-9 . _ : / = -`) is echoed back here and in the response header; a missing or invalid value is silently replaced with a generated `rq_…` id.
- `instance` (string): Pointer to the specific failing resource (e.g. `/items/12345`). Path-only, no `/v1` version prefix. Absent on unknown-path `404` and unexpected `500` responses.
- `code` (string): Sub-reason code surfaced from upstream BoxHero core (on core-mapped 4xx) or from the gateway itself (e.g. `not-available-for-api-token` on 403). Use this for fine-grained branching after dispatching on `type`.
- `errors` (array of object): Field-level error details. Present on request-validation `/errors/invalid-request` (400) responses. Absent on malformed-JSON `400`, `413` body-too-large, and most errors mapped from BoxHero core (which include it only when core supplies an array; this can include `403`). Each entry locates a single failure via JSONPath-like `path` segments and a human-readable `message`.

  - `path` (array of string | number, จำเป็น)
  - `message` (string, จำเป็น)

คำขอ

**cURL**

```bash
curl --request PUT \
  --url 'https://rest.boxhero-app.com/v1/purchase-orders/{order_id}' \
  --header "Authorization: Bearer $BOXHERO_API_TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{
    "memo": "Updated restock note",
    "costs": [
      {
        "name": "Shipping fee",
        "amount": "45.00"
      }
    ],
    "items": [
      {
        "id": 700101,
        "item_sku": "SKU-12345678",
        "quantity": 120,
        "price": "19.99"
      }
    ],
    "revision": 3
  }'
```

**JavaScript**

```javascript
const response = await fetch("https://rest.boxhero-app.com/v1/purchase-orders/{order_id}", {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${process.env.BOXHERO_API_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "memo": "Updated restock note",
    "costs": [
      {
        "name": "Shipping fee",
        "amount": "45.00"
      }
    ],
    "items": [
      {
        "id": 700101,
        "item_sku": "SKU-12345678",
        "quantity": 120,
        "price": "19.99"
      }
    ],
    "revision": 3
  }),
});
const data = await response.json();
```

**Python**

```python
import os
import requests

response = requests.put(
    "https://rest.boxhero-app.com/v1/purchase-orders/{order_id}",
    headers={
        "Authorization": "Bearer " + os.environ["BOXHERO_API_TOKEN"],
    },
    json={
        "memo": "Updated restock note",
        "costs": [
            {
                "name": "Shipping fee",
                "amount": "45.00",
            },
        ],
        "items": [
            {
                "id": 700101,
                "item_sku": "SKU-12345678",
                "quantity": 120,
                "price": "19.99",
            },
        ],
        "revision": 3,
    },
)
data = response.json()
```

**HTTP**

```http
PUT /v1/purchase-orders/{order_id} HTTP/1.1
Host: rest.boxhero-app.com
Authorization: Bearer <token>
Content-Type: application/json

{
  "memo": "Updated restock note",
  "costs": [
    {
      "name": "Shipping fee",
      "amount": "45.00"
    }
  ],
  "items": [
    {
      "id": 700101,
      "item_sku": "SKU-12345678",
      "quantity": 120,
      "price": "19.99"
    }
  ],
  "revision": 3
}
```

การตอบกลับ

**200**

```json
{
  "id": 90101
}
```

**400**

```json
{
  "id": "ex_8f5c0c8e0e0a4a3c9b3f4f2c4f6c8d2a",
  "correlationID": "rq_01abf3c2b8e44a59be2a9c0f1e7d6a40",
  "type": "/errors/invalid-request",
  "title": "Request validation failed (including an unknown item_sku/bundle_sku), core rejected the update, or the team is not in LOCATION mode.",
  "instance": "/purchase-orders/12345"
}
```

**401**

```json
{
  "id": "ex_8f5c0c8e0e0a4a3c9b3f4f2c4f6c8d2a",
  "correlationID": "rq_01abf3c2b8e44a59be2a9c0f1e7d6a40",
  "type": "/errors/tokens/required",
  "title": "Missing API token. Provide a Bearer token in the Authorization header.",
  "instance": "/purchase-orders/12345",
  "example": "Bearer wqnot0dlysdg5vymubzi4kiv"
}
```

**404**

```json
{
  "id": "ex_8f5c0c8e0e0a4a3c9b3f4f2c4f6c8d2a",
  "correlationID": "rq_01abf3c2b8e44a59be2a9c0f1e7d6a40",
  "type": "/errors/not-found",
  "title": "No purchase order with the given id was found in this team.",
  "instance": "/purchase-orders/12345"
}
```

**409**

```json
{
  "id": "ex_8f5c0c8e0e0a4a3c9b3f4f2c4f6c8d2a",
  "correlationID": "rq_01abf3c2b8e44a59be2a9c0f1e7d6a40",
  "type": "/errors/invalid-request",
  "title": "The supplied revision is stale.",
  "instance": "/purchase-orders/12345"
}
```

**413**

```json
{
  "id": "ex_8f5c0c8e0e0a4a3c9b3f4f2c4f6c8d2a",
  "correlationID": "rq_01abf3c2b8e44a59be2a9c0f1e7d6a40",
  "type": "/errors/invalid-request",
  "title": "Request body is too large.",
  "instance": "/purchase-orders/12345"
}
```

**429**

```json
{
  "id": "ex_8f5c0c8e0e0a4a3c9b3f4f2c4f6c8d2a",
  "correlationID": "rq_01abf3c2b8e44a59be2a9c0f1e7d6a40",
  "type": "/errors/too-many-requests",
  "title": "Too many requests.",
  "instance": "/purchase-orders/12345",
  "retryAfter": 60
}
```
