Line items

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

Subscriptions docs
On this page

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.

Request body

FieldTypeRequiredDescription
contractIdstring|numberYesShopify GID or numeric ID of the contract.
variantIdstring|numberYesShopify GID (gid://shopify/ProductVariant/123) or numeric ID of the variant to add.
quantitynumberYesWhole number from 1 to 1000000.
pricenumberNoPer-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.
currencyCodestringNoThree-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

FieldTypeRequiredDescription
contractIdstring|numberYesShopify GID or numeric ID of the contract.
lineIdstringYesThe line's id from list contracts — the full gid://shopify/SubscriptionLine/… GID or the part after the last /.
variantIdstring|numberNoMove the line to this variant.
quantitynumberNoNew quantity, a whole number from 1 to 1000000.
pricenumberNoNew per-unit price in the contract's currency, with the same rules as for adding a line.
currencyCodestringNoChecked 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.

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 it instead.

Request body

FieldTypeRequiredDescription
contractIdstring|numberYesShopify GID or numeric ID of the contract.
lineIdstringYesThe line's id from 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 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.

Can’t find what you need?

Ask the Kaching team about your integration in chat.