Shopify Post-Purchase Checkout Extension - How to get the order Id?

Topic summary

Goal: obtain the order ID in a Shopify post‑purchase checkout extension to tag or link upsell edits to the original order.

Approaches discussed:

  • Metafield tagging via signChangeset: add a set_metafield (e.g., namespace: app name, key: isUpsellOrder, value: 1) alongside add_variant in the changes array. Then subscribe to order webhooks and query the Order Metafields endpoint (/admin/api/2021-07/orders/{orderId}/metafields.json) to detect the flag and associate the upsell with its order ID.
  • Reference mapping: use the extension’s referenceId (from shouldRender input) and match it to the order webhook’s checkout_token to identify the order and thus its ID. Initial doubt about referenceId in webhooks was resolved by testing that showed referenceId = checkout_token worked reliably for some.

Latest status: multiple participants report success using referenceId ↔ checkout_token; one user confirms “working as expected.” Another asks if this is the final solution and how webhooks were accessed; no definitive closure provided.

Notes: code snippets (changes array and metafield API call) are central. Terms: metafields = key‑value on orders; signChangeset = API to modify post‑purchase orders; checkout_token = identifier in order webhook payload.

Summarized with AI on January 4. AI used: gpt-5.

It’s looking pretty good, everything’s working as expected for me when using referenceId as the checkoutToken.

2 Likes