Skip to main content

Update a subscription contract

Subscription contracts often require updates, such as when a customer needs to update their payment method or requests a change to their subscription.

This guide shows you how to submit the desired changes to subscriptionContractUpdateCalculate, review Shopify's calculated result, and commit a new active version of the contract. Fields that you omit remain unchanged.

Available in API version 2026-10 and later

The SubscriptionContractCalculation API is available in GraphQL Admin API version 2026-10 and later. If your app uses the SubscriptionDraft API, refer to the legacy contract update guide.


Note

Anchor to How contract calculation worksHow contract calculation works

Contract updates use an asynchronous calculate and commit flow:

  1. Query the current contract state.
  2. Submit the fields that you want to change.
  3. Poll the calculation or wait for a webhook. Shopify emits subscription_contract_calculations/succeed when a calculation succeeds and subscription_contract_calculations/fail when it fails or is voided.
  4. Review the complete calculated contract, projected totals, warnings, or errors.
  5. Commit a successful calculation.

Committing creates a new version of the contract. It doesn't modify orders or fulfillments that have already been created. Use orderEditBegin to edit an existing order.


Anchor to Step 1: Query the subscription contractStep 1: Query the subscription contract

Query the contract before calculating an update. Include the IDs and complete values for any collection that you plan to replace, such as lines or manual discounts. When you rebuild the lines array, a line's variantId is the value that you pass as productVariantId in the input:

POST https://{shop}.myshopify.com/admin/api/2026-10/graphql.json

GraphQL query

query GetSubscriptionContract($id: ID!) {
subscriptionContract(id: $id) {
id
status
note
lines(first: 50) {
nodes {
id
quantity
variantId
currentPrice {
amount
currencyCode
}
customAttributes {
key
value
}
}
}
billingPolicy {
interval
intervalCount
}
deliveryPolicy {
interval
intervalCount
}
deliveryMethod {
__typename
}
customerPaymentMethod {
id
}
}
}

Variables

{
"id": "gid://shopify/SubscriptionContract/123"
}

Anchor to Step 2: Calculate the updateStep 2: Calculate the update

Call subscriptionContractUpdateCalculate with the contract ID and desired changes. The following example changes an existing line's quantity and applies a discount code. Because lines replaces the entire collection, this example assumes a single-line contract. For a contract with multiple lines, include every line you want to keep:

POST https://{shop}.myshopify.com/admin/api/2026-10/graphql.json

GraphQL mutation

mutation UpdateSubscriptionContract {
subscriptionContractUpdateCalculate(
contractId: "gid://shopify/SubscriptionContract/123"
contractUpdateInput: {
withMerchandiseCustomizations: true
lines: [
{
productVariantLine: {
id: "gid://shopify/SubscriptionLine/existing-line-uuid"
productVariantId: "gid://shopify/ProductVariant/111"
quantity: 2
customAttributes: []
discounts: []
}
}
]
discountCodes: [{ redeemCode: "SAVE10" }]
}
) {
subscriptionContractCalculation {
... on SubscriptionContractCalculationPending {
id
}
}
userErrors {
field
message
code
}
}
}

JSON response

{
"data": {
"subscriptionContractUpdateCalculate": {
"subscriptionContractCalculation": {
"id": "gid://shopify/SubscriptionContractCalculation/789"
},
"userErrors": []
}
}
}

If the mutation returns a user error, then correct the input before polling. Shopify doesn't create an asynchronous calculation when input validation fails.

Collections replace existing values

When you provide lines or manualDiscounts, the array replaces the complete existing collection. Include the IDs and values for every existing item that you want to keep. Omit an existing item to remove it, and omit id from a new item.

Providing a line also replaces that line's customAttributes and discounts, and you must state both whenever you include the line. Pass the line's existing customAttributes (queried in Step 1) and re-declare any line-level discounts to keep them, or pass an empty list to clear either.


Anchor to Step 3: Poll for the calculation resultStep 3: Poll for the calculation result

The calculate mutation returns a pending calculation. Poll for the result and review it before committing.

Contract calculations run asynchronously. Most calculations finish in less than three seconds, but Functions and external services can increase processing time. Use the calculation ID returned by the calculate mutation to query subscriptionContractCalculation:

POST https://{shop}.myshopify.com/admin/api/2026-10/graphql.json

GraphQL query

query PollSubscriptionContractCalculation($id: ID!) {
subscriptionContractCalculation(id: $id) {
__typename
... on SubscriptionContractCalculationPending {
id
}
... on SubscriptionContractCalculationSuccess {
id
calculatedContract {
lines(first: 10) {
nodes {
id
quantity
title
variantId
}
}
}
warnings {
code
message
}
projectedOrderTotals {
subtotal {
amount
currencyCode
}
totalDelivery {
amount
currencyCode
}
totalTax {
amount
currencyCode
}
totalMerchandiseDiscounts {
amount
currencyCode
}
totalDeliveryDiscounts {
amount
currencyCode
}
total {
amount
currencyCode
}
}
}
... on SubscriptionContractCalculationFailure {
id
errors {
code
message
}
}
}
}

Variables

{
"id": "gid://shopify/SubscriptionContractCalculation/789"
}

Pending response

{
"data": {
"subscriptionContractCalculation": {
"__typename": "SubscriptionContractCalculationPending",
"id": "gid://shopify/SubscriptionContractCalculation/789"
}
}
}

The query returns one of the following types:

TypeMeaningAction
SubscriptionContractCalculationPendingShopify initiated or is processing the calculation.Continue polling.
SubscriptionContractCalculationSuccessThe calculated contract is ready to review and commit.Review the result before committing.
SubscriptionContractCalculationFailureThe calculation failed (processed with errors) or Shopify voided it (never processed, for example, because of an infrastructure issue).If it failed, read errors and correct the input before calculating again. If it was voided, errors is empty and there's nothing to fix in the input, so retry the calculation.

Wait two seconds before the first poll, poll every second, and stop after 30 seconds. If the calculation is still pending, then retry later or wait for a webhook instead of increasing the polling frequency.

Anchor to Review the calculated contractReview the calculated contract

Before committing, inspect the following fields on SubscriptionContractCalculationSuccess:

  • calculatedContract: The complete contract snapshot that the commit applies.
  • projectedOrderTotals: The projected merchandise, delivery, discount, tax, and total amounts.
  • warnings: Existing-data or compatibility problems that don't prevent the calculation from succeeding.

A successful calculation is immutable. If you need to change the input, then start a new calculation and commit only the result that you want to make active.

Review warnings

A successful calculation can contain warnings. Review them before committing because they can identify disabled currencies, delivery configuration problems, or other existing contract data that Shopify preserved instead of blocking the update.

Anchor to Use webhooks instead of pollingUse webhooks instead of polling

For event-driven processing, subscribe to the following webhook topics:

TopicDescription
subscription_contract_calculations/succeedThe calculation succeeded and is ready to review and commit.
subscription_contract_calculations/failThe calculation failed or Shopify voided it. A failed calculation has errors to query; a voided one has empty errors, so retry it.

Create a webhook subscription with webhookSubscriptionCreate:

POST https://{shop}.myshopify.com/admin/api/2026-10/graphql.json

GraphQL mutation

mutation CreateCalculationWebhook {
webhookSubscriptionCreate(
topic: SUBSCRIPTION_CONTRACT_CALCULATIONS_SUCCEED
webhookSubscription: {
uri: "https://example.com/webhooks/calculation-success"
format: JSON
}
) {
webhookSubscription {
id
}
userErrors {
field
message
}
}
}

Webhook payload

{
"id": 789,
"admin_graphql_api_id": "gid://shopify/SubscriptionContractCalculation/789",
"state": "succeeded"
}

Use admin_graphql_api_id to query the completed calculation. Webhook delivery doesn't commit the result automatically.


Anchor to Step 4: Commit the calculationStep 4: Commit the calculation

After the calculation succeeds and you've reviewed the result, call subscriptionContractCalculationCommit. The commit makes the calculated contract active for billing:

POST https://{shop}.myshopify.com/admin/api/2026-10/graphql.json

GraphQL mutation

mutation CommitSubscriptionContractCalculation {
subscriptionContractCalculationCommit(
id: "gid://shopify/SubscriptionContractCalculation/789"
) {
contract {
... on SubscriptionContract {
id
status
}
}
userErrors {
field
message
code
}
}
}

JSON response

{
"data": {
"subscriptionContractCalculationCommit": {
"contract": {
"id": "gid://shopify/SubscriptionContract/999",
"status": "ACTIVE"
},
"userErrors": []
}
}
}

Handle commit user errors by code:

CodeMeaningAction
NOT_READY_TO_COMMITThe calculation hasn't succeeded yet.Continue polling before retrying the commit.
CALCULATION_NOT_FOUNDThe calculation ID doesn't exist or isn't available to the app.Verify the ID and app access.
STALE_CONTRACTThe contract changed after this calculation started.Query the latest contract state and calculate again.
INVALIDShopify can't commit the calculation.Use field and message to correct the request.

You can safely retry polling and commit requests. Retrying a calculate mutation creates a new calculation, so retain the ID for the result that you intend to commit. Retrying a commit for an already committed calculation returns the committed result.


Anchor to Update common contract attributesUpdate common contract attributes

Use the following update semantics when preparing contractUpdateInput:

InputBehavior
withMerchandiseCustomizationsRequired. Set to true to run merchandise transformations, both fixed bundle expansion from a stored definition and Shopify Functions that customize merchandise, such as cart transforms. Set to false to bypass all merchandise transformations.
linesReplaces all lines. Include an id to keep or update an existing line. Omit id to add a line. Omit the field to leave all lines unchanged.
manualDiscountsReplaces all manual order and delivery discounts. Pass [] to remove all manual discounts.
discountCodesApplies codes during this calculation. Shopify resolves them into manual discounts on the contract instead of storing the codes.
billingPolicyReplaces the billing cadence and anchors.
deliveryPolicyReplaces the delivery anchors and optional multi-fulfillment configuration.
deliveryMethodReplaces the delivery method. Pass none to remove it, or fetchAvailableDeliveryOptions to discover options without changing the committed method. The resulting discovery calculation can't be committed.
paymentMethodReplaces the payment method. Pass none to remove it.
paymentConfigurationAvailable in GraphQL Admin API version 2027-01 and later. Replaces the store credit setting with allowStoreCredit. A value of true must pass the selling plan rule. Omit allowStoreCredit to keep the current setting.
noteReplaces the note. Pass null to clear it.
customAttributesReplaces all contract attributes. Pass [] to remove them.
appManagedBillingConfigReplaces app-managed minCycles and maxCycles metadata. These are stored on the contract but don't affect calculated billing cycle dates.

Manage contract status separately with subscriptionContractActivate, subscriptionContractPause, subscriptionContractCancel, subscriptionContractExpire, or subscriptionContractFail.

Anchor to Discover delivery optionsDiscover delivery options

To retrieve shipping options for a new address without changing the committed delivery method, provide fetchAvailableDeliveryOptions:

deliveryMethod: {
fetchAvailableDeliveryOptions: {
address: {
lastName: "Ishida"
address1: "123 Main St"
city: "Toronto"
provinceCode: "ON"
countryCode: CA
zip: "M5V 1A1"
}
withDeliveryCustomizations: true
}
}

When you poll the calculation in Step 3, read the results from the deliveryOptions field on SubscriptionContractCalculationSuccess, a union of shipping, local delivery, and pickup options. A calculation that provides fetchAvailableDeliveryOptions is a discovery calculation and can't be committed. Read the options, then create a new calculation with the chosen delivery method, and commit it. Delivery customization Functions run only when withDeliveryCustomizations is true.


Anchor to Update a contract that has billing cycle editsUpdate a contract that has billing cycle edits

A billing cycle edit changes one billing cycle. A contract edit changes the contract information of the cycle, and a schedule edit skips the cycle or changes its billing date.

A current or upcoming contract edit blocks every update of the contract, and subscriptionContractUpdateCalculate returns the CONTRACT_HAS_FUTURE_EDITS error code. A schedule edit doesn't block an update.

To update a contract that has a contract edit:

  1. Stop making billing cycle edits on the contract, in your app and in its customer portal, until step 5 is done. This includes skips, billing date changes, and commits of contract edits. If a cycle of the contract is combined with cycles of other contracts, then stop the edits on those contracts too, because step 3 also deletes the edits of those cycles. Shopify doesn't lock the contracts between your requests, so step 3 also deletes an edit that's made after step 2, and you have no record of that edit.
  2. Record every current and upcoming billing cycle edit of the contract. Step 3 deletes all of them, and you can't undo it.
  3. Delete the edits with subscriptionBillingCycleEditsDelete. The mutation deletes all current and upcoming edits of the contract, including the schedule edits. A cycle that the customer skipped is no longer skipped, and a cycle with a new billing date goes back to its original date. For a combined cycle, the mutation also deletes the edits of every other cycle in the group, including the schedule edits of the cycles on the other contracts, and the cycles are no longer combined.
  4. Calculate and commit the update.
  5. Reapply the edits that you recorded, on each contract that lost them. To bill a group as one order again, combine its cycles again.

Use subscriptionBillingCycles to find the cycles that have an edit. The query returns only the cycles in the range that you select, one page at a time. The delete mutation has no range and no pages. You can't reapply an edit that you didn't record, so don't delete the edits until your record covers every cycle that can have an edit:

  • The query requires a date range in billingCyclesDateRangeSelector, or an index range in billingCyclesIndexRangeSelector. Use a range that starts at the current cycle and ends after the furthest cycle that your app or a customer portal can edit.
  • The result is paginated, and a page returns up to 250 cycles. Request pageInfo, and while hasNextPage is true, repeat the query with after set to endCursor.

The following example reads one page of the cycles in a date range. To read the next page, pass the endCursor value as the after variable:

POST https://{shop}.myshopify.com/admin/api/2026-10/graphql.json

GraphQL query

query GetEditedBillingCycles(
$contractId: ID!
$startDate: DateTime!
$endDate: DateTime!
$after: String
) {
subscriptionBillingCycles(
contractId: $contractId
billingCyclesDateRangeSelector: { startDate: $startDate, endDate: $endDate }
first: 50
after: $after
) {
nodes {
cycleIndex
edited
skipped
billingAttemptExpectedDate
editedContract {
createdAt
}
}
pageInfo {
hasNextPage
endCursor
}
}
}

Variables

{
"contractId": "gid://shopify/SubscriptionContract/123",
"startDate": "2026-11-01T00:00:00Z",
"endDate": "2027-11-01T00:00:00Z",
"after": null
}

For each cycle that has edited: true, record everything that your app needs to make the edit again:

  • The schedule edit: record skipped and billingAttemptExpectedDate.
  • The contract edit: a cycle that has one returns an editedContract, and a cycle that has only a schedule edit returns null. Record each value that your app's edits can change. For an edit with subscriptionBillingCycleContractEditCalculate, that's the lines, the manual discounts, the delivery method, the note, and the custom attributes. If the edited contract has more lines or discounts than a page returns, then read every page.
  • The group: if the cycle is combined with cycles of other contracts, then editedContract.billingCycles lists every cycle in the group. Record the sourceContract, the cycleIndex, and the schedule edit of each of those cycles. If you didn't stop the edits on those contracts yet, then stop them as in step 1, and read the group again. Read the group in one page, with first: 250, and don't page through it. If pageInfo.hasNextPage is true, then the page doesn't hold the whole group and your record isn't complete, so don't delete the edits.

The following example reads the contract edit and the group of one cycle. Add each field that your app's edits set, such as the fields of the delivery method:

POST https://{shop}.myshopify.com/admin/api/2026-10/graphql.json

GraphQL query

query GetBillingCycleContractEdit($contractId: ID!, $cycleIndex: Int!) {
subscriptionBillingCycle(
billingCycleInput: { contractId: $contractId, selector: { index: $cycleIndex } }
) {
cycleIndex
skipped
billingAttemptExpectedDate
editedContract {
note
customAttributes {
key
value
}
lines(first: 50) {
nodes {
id
quantity
variantId
currentPrice {
amount
currencyCode
}
customAttributes {
key
value
}
}
pageInfo {
hasNextPage
endCursor
}
}
discounts(first: 25) {
nodes {
id
title
targetType
recurringCycleLimit
value {
... on SubscriptionDiscountFixedAmountValue {
amount {
amount
currencyCode
}
appliesOnEachItem
}
... on SubscriptionDiscountPercentageValue {
percentage
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
deliveryMethod {
__typename
}
billingCycles(first: 250) {
nodes {
cycleIndex
skipped
billingAttemptExpectedDate
sourceContract {
id
}
}
pageInfo {
hasNextPage
}
}
}
}
}

Variables

{
"contractId": "gid://shopify/SubscriptionContract/123",
"cycleIndex": 3
}

The following example deletes all current and upcoming edits of a contract:

POST https://{shop}.myshopify.com/admin/api/2026-10/graphql.json

GraphQL mutation

mutation DeleteBillingCycleEdits {
subscriptionBillingCycleEditsDelete(
contractId: "gid://shopify/SubscriptionContract/123"
targetSelection: ALL
) {
billingCycles {
cycleIndex
edited
skipped
}
userErrors {
field
message
code
}
}
}

JSON response

{
"data": {
"subscriptionBillingCycleEditsDelete": {
"billingCycles": [
{
"cycleIndex": 3,
"edited": false,
"skipped": false
},
{
"cycleIndex": 4,
"edited": false,
"skipped": false
}
],
"userErrors": []
}
}
}

The mutation can fail in the following cases:

  • A targeted billing cycle has an incomplete billing attempt. The mutation returns the INCOMPLETE_BILLING_ATTEMPTS error code on targetSelection, and it deletes nothing. Retry the mutation after the billing attempts complete.
  • No targeted billing cycle has an edit. The mutation returns the NO_CYCLE_EDITS error code. In that case, you can update the contract right away.


Was this page helpful?