Skip to main content

Sync orders and subscriptions

When an order is created by Shopify, and delivery anchors exist, the order contains delayed fulfillment orders for prepaid items. This guide describes how to keep your orders and subscription contracts in sync, and covers some common order management scenarios that relate to fulfillment orders and subscription contracts.

Caution

Order editing in the Shopify admin isn't supported for orders with prepaid subscriptions.


Anchor to Keeping orders and subscription contracts in syncKeeping orders and subscription contracts in sync

Changes to prepaid subscription contracts aren't automatically reflected on the associated orders. For example, when a customer updates their address for a prepaid subscription in an app, their address isn't automatically updated in the order.

The following diagram shows the required actions that your app must take to sync updates for prepaid subscription contracts:

Workflow for interacting with fulfillment orders and subscription contracts
Tip

Learn how to interact with the SubscriptionDraft object by completing the Update a subscription contract tutorial.

Anchor to Managing cancellationsManaging cancellations

The cancellation of orders doesn't automatically cancel related subscription contracts. It's recommended that apps subscribe to the orders/cancel webhook and communicate with merchants when subscription contract orders are cancelled, so that merchants know that the subscription contract hasn't also been cancelled.

Anchor to Subscription cancellation through a customer portalSubscription cancellation through a customer portal

When a customer cancels a subscription order through the customer portal, apps need to notify the merchant of this cancellation. If the cancellation is initiated through the app, then the app needs to handle the associated refunds. This applies to both prepaid and subscribe-and-save subscriptions.


Merchants often identify and filter subscription orders in the Shopify admin. To tag orders for subscriptions from your app, you can call the tagsAdd mutation. The following example adds tags to a specified order using the order ID:

POST https://{shop}.myshopify.com/admin/api/{api_version}/graphql.json

GraphQL mutation

mutation tagsAdd($id: ID!, $tags: [String!]!) {
tagsAdd(id: $id, tags: $tags) {
node {
id
}
userErrors {
field
message
}
}
}

Variables

{
"id": "gid://shopify/Order/2067697074232",
"tags": ["subscription", "prepaid"]
}

JSON response

{
"data": {
"orderUpdate": {
"order": {
"id": "gid://shopify/Order/2067697074232"
},
"userErrors": []
}
}
}

Anchor to Automatic fulfillmentAutomatic fulfillment

Scheduled fulfillment orders aren't eligible for automatic fulfillment. However, if a prepaid subscription order is created with its first fulfillment order set to the OPEN state, then the fulfillment order is automatically fulfilled.


Apps that use CSV exports to manage fulfillments can rely on the value of lineItem.fulfillableQuantity to determine which orders are ready to fulfill. This is because SCHEDULED fulfillment orders aren't included in the calculation of the order lineItem.fulfillableQuantity.

For example, consider a fulfillment order scheduled to ship on January 15. Before January 15, lineItem.fulfillableQuantity is set to 0. After January 15, lineItem.fulfillableQuantity is set to 1. Then, after the item is fulfilled, lineItem.fulfillableQuantity is set back to 0.


Your app can subscribe to order webhooks that are useful for apps that manage fulfillment orders for merchants. The following examples show the JSON responses from each of the available webhooks.

To learn how to set up and consume webhooks, refer to Webhooks configuration.

Example webhook responses

// Occurs when an order is created. Subscription apps need to query the order's line items for their selling plan to determine whether this is a subscription order that they own.
{
"id": 820982911946154508,
"email": "jon@doe.ca",
"closed_at": null,
"created_at": "2022-10-03T12:55:00-04:00",
"updated_at": "2022-10-03T12:55:00-04:00",
"number": 234,
"note": null,
"token": "123456abcd",
"gateway": null,
"test": true,
"total_price": "403.00",
"subtotal_price": "393.00",
"total_weight": 0,
"total_tax": "0.00",
"taxes_included": false,
"currency": "USD",
"financial_status": "voided",
"confirmed": false,
"total_discounts": "5.00",
"total_line_items_price": "398.00",
"cart_token": null,
"buyer_accepts_marketing": true,
"name": "#9999",
"referring_site": null,
"landing_site": null,
"cancelled_at": "2022-10-03T12:55:00-04:00",
"cancel_reason": "customer",
"total_price_usd": null,
"checkout_token": null,
"reference": null,
"user_id": null,
"location_id": null,
"source_identifier": null,
"source_url": null,
// Occurs when an order is updated or when a scheduled fulfillment order is transitioned to the `OPEN` state. For example, this webhook can be used to track address updates.
{
"id": 820982911946154508,
"email": "jon@doe.ca",
"closed_at": null,
"created_at": "2022-10-03T12:55:00-04:00",
"updated_at": "2022-10-03T12:55:00-04:00",
"number": 234,
"note": null,
"token": "123456abcd",
"gateway": null,
"test": true,
"total_price": "403.00",
"subtotal_price": "393.00",
"total_weight": 0,
"total_tax": "0.00",
"taxes_included": false,
"currency": "USD",
"financial_status": "voided",
"confirmed": false,
"total_discounts": "5.00",
"total_line_items_price": "398.00",
"cart_token": null,
"buyer_accepts_marketing": true,
"name": "#9999",
"referring_site": null,
"landing_site": null,
"cancelled_at": "2022-10-03T12:55:00-04:00",
"cancel_reason": "customer",
"total_price_usd": null,
"checkout_token": null,
"reference": null,
"user_id": null,
"location_id": null,
"source_identifier": null,
"source_url": null,
// Occurs when an order is cancelled. Subscription apps can use this webhook to ensure the related contract is cancelled as well, if that's the merchant's intention.
{
"id": 820982911946154508,
"email": "jon@doe.ca",
"closed_at": null,
"created_at": "2022-10-03T12:55:00-04:00",
"updated_at": "2022-10-03T12:55:00-04:00",
"number": 234,
"note": null,
"token": "123456abcd",
"gateway": null,
"test": true,
"total_price": "403.00",
"subtotal_price": "393.00",
"total_weight": 0,
"total_tax": "0.00",
"taxes_included": false,
"currency": "USD",
"financial_status": "voided",
"confirmed": false,
"total_discounts": "5.00",
"total_line_items_price": "398.00",
"cart_token": null,
"buyer_accepts_marketing": true,
"name": "#9999",
"referring_site": null,
"landing_site": null,
"cancelled_at": "2022-10-03T12:55:00-04:00",
"cancel_reason": "customer",
"total_price_usd": null,
"checkout_token": null,
"reference": null,
"user_id": null,
"location_id": null,
"source_identifier": null,
"source_url": null,
// Occurs when a refund is created. This webhook can be used to ensure contracts get updated as well, if that's the merchant's intention.
{
"id": 890088186047892319,
"order_id": 820982911946154508,
"created_at": null,
"note": "Things were damaged",
"user_id": 548380009,
"processed_at": null,
"restock": false,
"duties": [

],
"total_duties_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"admin_graphql_api_id": "gid:\/\/shopify\/Refund\/890088186047892319",
"refund_line_items": [
{
"id": 866550311766439093,
"quantity": 1,
"line_item_id": 866550311766439020,
"location_id": null,
"restock_type": "no_restock",
"subtotal": 199.0,
"total_tax": 0.0,
"subtotal_set": {
"shop_money": {
"amount": "199.00",
"currency_code": "USD"
Note

To know when items should be fulfilled, apps should query fulfillmentOrders when they receive the orders/create webhook. If apps don't query fulfillmentOrders and submit a request to create fulfillments for items that shouldn't be fulfilled yet, then the request fails.



Was this page helpful?