# Line items

Change what a subscription contains: add, update and remove a contract's line items.

https://www.kachingappz.com/developers/subscriptions/line-items/ · Updated 2026-11-23

Change what a subscription contains. These endpoints alter what the customer receives and pays, so read the notes at the end of the group before wiring them up.

## Add a line item to a contract

```http
POST /shop-api/contracts/add-line-item
```

Permission: **Line items** → Add line items (`contracts:add_line_item`).

Adds a product variant to a contract. The new line rides the contract's existing billing schedule and appears in `lines` the next time you [list contracts](https://www.kachingappz.com/developers/subscriptions/contracts/#list-contracts).

**Request body**

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `contractId` | string\|number | Yes | Shopify GID or numeric ID of the contract. |
| `variantId` | string\|number | Yes | Shopify GID (`gid://shopify/ProductVariant/123`) or numeric ID of the variant to add. |
| `quantity` | number | Yes | Whole number from 1 to 1000000. |
| `price` | number | No | **Per-unit** price in the contract's currency: 0 or more, at most 2 decimals, up to 1000000. Omit it to price the line at the variant's price for the contract's delivery country. |
| `currencyCode` | string | No | Three-letter currency code. A check, not a conversion: the request is refused if it differs from the contract's `currencyCode`. |

**How the line is priced**

- **With \`price\`** — the line is contracted at that price on every future order. The contract's selling plan cannot re-price it later.
- **Without \`price\`** — the line is priced at the variant's price for the market the contract ships to, in the contract's currency. If the variant has no price in that currency, the request is refused with `422` and nothing is added.

**Example**

```bash
curl -X POST "https://subscriptions.kachingappz.app/shop-api/contracts/add-line-item" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "contractId": "123456789",
    "variantId": "44123456789",
    "quantity": 2,
    "price": 25.99,
    "currencyCode": "USD"
  }'
```

**Response (200)**

```json
{
  "success": true,
  "line": {
    "id": "gid://shopify/SubscriptionLine/0f1dcb8f-e608-4c3f-b153-dc77897d39e9",
    "variantId": "gid://shopify/ProductVariant/44123456789",
    "quantity": 2,
    "price": 25.99,
    "currencyCode": "USD",
    "priceSource": "REQUEST"
  }
}
```

`priceSource` is `REQUEST` when the price is the one you sent, and `CONTEXTUAL` when it was taken from the contract's market.

---

## Update a line item

```http
POST /shop-api/contracts/update-line-item
```

Permission: **Line items** → Update line items (`contracts:update_line_item`).

Changes the variant, quantity and/or price of an existing line. Send at least one of `variantId`, `quantity` and `price`.

**Request body**

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `contractId` | string\|number | Yes | Shopify GID or numeric ID of the contract. |
| `lineId` | string | Yes | The line's `id` from [list contracts](https://www.kachingappz.com/developers/subscriptions/contracts/#list-contracts) — the full `gid://shopify/SubscriptionLine/…` GID or the part after the last `/`. |
| `variantId` | string\|number | No | Move the line to this variant. |
| `quantity` | number | No | New quantity, a whole number from 1 to 1000000. |
| `price` | number | No | New **per-unit** price in the contract's currency, with the same rules as for [adding a line](https://www.kachingappz.com/developers/subscriptions/line-items/#add-a-line-item-to-a-contract). |
| `currencyCode` | string | No | Checked against the contract's currency, as for adding a line. |

**What each field changes**

- **\`quantity\`** — only the quantity. The line's price and discount schedule are left as they are.
- **\`variantId\`** — the line moves to the new variant **at the price it already has**. A variant swap never changes what the customer pays; send `price` as well if it should.
- **\`price\`** — the line is contracted at the new price on every future order, replacing any discount schedule it had.

> **Warning** Lowering `quantity` can remove a discount. A flat-amount discount sized for the old quantity (for example "buy 2, get 1 free") would take the line to zero or below at the new one, so it is taken off in the same change and listed in `removedDiscounts`. Discounts that apply to other lines are never touched.

**Example — swap the variant and change the quantity**

```bash
curl -X POST "https://subscriptions.kachingappz.app/shop-api/contracts/update-line-item" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "contractId": "123456789",
    "lineId": "gid://shopify/SubscriptionLine/0f1dcb8f-e608-4c3f-b153-dc77897d39e9",
    "variantId": "44987654321",
    "quantity": 3
  }'
```

**Response (200)**

```json
{
  "success": true,
  "line": {
    "id": "gid://shopify/SubscriptionLine/0f1dcb8f-e608-4c3f-b153-dc77897d39e9",
    "variantId": "gid://shopify/ProductVariant/44987654321",
    "quantity": 3,
    "price": 25.99,
    "currencyCode": "USD",
    "priceSource": "REQUEST"
  },
  "removedDiscounts": []
}
```

Each entry in `removedDiscounts` is `{ "discountId": "gid://shopify/SubscriptionManualDiscount/…", "reason": "quantity-invalidated" }`.

---

## Remove a line item

```http
POST /shop-api/contracts/remove-line-item
```

Permission: **Line items** → Remove line items (`contracts:remove_line_item`).

Removes a line from a contract. The contract's last line cannot be removed — to stop a subscription, [cancel](https://www.kachingappz.com/developers/subscriptions/contracts/#cancel-a-contract) it instead.

**Request body**

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `contractId` | string\|number | Yes | Shopify GID or numeric ID of the contract. |
| `lineId` | string | Yes | The line's `id` from [list contracts](https://www.kachingappz.com/developers/subscriptions/contracts/#list-contracts). |

**Example**

```bash
curl -X POST "https://subscriptions.kachingappz.app/shop-api/contracts/remove-line-item" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "contractId": "123456789",
    "lineId": "gid://shopify/SubscriptionLine/0f1dcb8f-e608-4c3f-b153-dc77897d39e9"
  }'
```

**Response (200)**

```json
{
  "success": true,
  "lineId": "gid://shopify/SubscriptionLine/0f1dcb8f-e608-4c3f-b153-dc77897d39e9"
}
```

---

## Notes on line item changes

- **Only \`ACTIVE\`, \`PAUSED\` and \`FAILED\` contracts can be changed.** Others are refused with `422`, and so is a contract with more than 50 line items.
- **Changes apply to every future order**, not just the next one.
- **Every call applies — repeat calls are not deduplicated.** Two identical `add-line-item` requests add **two** lines. A request that timed out may still have been applied, so read [list contracts](https://www.kachingappz.com/developers/subscriptions/contracts/#list-contracts) before retrying.
- **Each call is its own change.** To replace one product with another, either swap the variant with `update-line-item`, or add the new line and then remove the old one — and if you do the latter, check the contract afterwards, since a failure in between leaves both lines or neither.
- **Lines given as a streak reward cannot be changed or removed** (`403`).
- **If the contract is being changed by something else at that moment**, the request is refused with `409`. Nothing was applied, so retry after a short wait.
- **The merchant's contract-update guard applies.** If the shop has it turned on, a change that takes the contract's total above both $100 USD and twice the value of its first order is refused with `422`.
- **Every change appears on the contract's timeline** in the Kaching admin as a "via API" entry.

---
