Skip to content
New

Shopify launched Agentic Storefronts. We make AI agents recommend you - not just list you.

See the Shopify integration
Tru Commerce

← Insights

Agent orders: promotion, variant and webhook tests

Test agent orders for correct variants, applicable discounts and reliable webhook processing. Use current Shopify contracts and practical merchant checks.

Tru Commerce Team · November 26, 2026 · Checkout & Protocols

Agent orders need the same commercial precision as storefront orders: the intended variant, an applicable promotion and a verifiable merchant state. These are separate integration contracts. A successful tool response does not prove that the right item received a discount or that the resulting order was processed once.

Reviewed 26 November 2026. This guide uses current Shopify API and webhook documentation to build a proposed merchant acceptance pack. It does not report an observed customer failure rate. Tru Commerce builds commerce integrations.

Preserve the selected variant through every operation

A shopper's product request and the merchandise identifier sent to a cart are not the same record. Resolve the request to an actual variant and preserve the selected options, quantity and any selling plan. If the request is ambiguous, ask a clarifying question or present distinct choices.

An illustrative case is a blue medium shirt and a blue large shirt. Both match a generic product description. Only one matches the buyer's selection. Changing the quantity should not silently reset the size; changing the size should trigger a fresh check of the resulting merchandise and offer.

Shopify's cartLinesUpdate reference supports updating quantity, merchandise, custom attributes and selling plan. It distinguishes omitted or null attributes, which preserve existing attributes, from an empty array, which clears them. Its response includes the cart, user errors and warnings. Test those semantics rather than treating every HTTP success as a successful requested change.

Keep the mapping explicit in your product-data API contract. The out-of-stock guide covers freshness; this guide focuses on preserving the approved selection while the basket changes.

A submitted discount code is not an applied discount

Shopify's cartDiscountCodesUpdate replaces the current code list with the supplied list. An empty array removes the codes. Codes are case-insensitive, and the documentation instructs integrations to inspect each returned code's applicability to the current cart.

That distinction belongs in the buyer experience. An agent should not announce a saving merely because it sent a code. It should inspect the authoritative cart and explain whether the promotion applied. If the basket changes, recheck the outcome rather than retaining the earlier savings sentence.

For example, a promotion might be applicable before a product is removed and inapplicable afterward. The test should verify the current cart outcome and revised total. This is an illustrative test condition; the actual eligibility rules belong to the merchant's configured promotion engine.

Avoid blanket claims that agents cannot submit promotion codes or that every protocol supports the same discount fields. The integration route, platform version and enabled extension determine the contract. When implementing ACP or UCP, verify the negotiated feature rather than copying a storefront assumption.

Test the basket as a sequence, not an isolated mutation

Most useful failures appear after a change. Run a small sequence that adds an item, updates a variant, applies a code and then changes the basket again. Record the authoritative state after each step and compare it with the agent's message.

Test fixtureOperationEvidence to inspect
Valid product with two sizesChange the selected sizeReturned merchandise and displayed size agree
Existing line attributesUpdate quantity without attributesExisting attributes remain when the contract says they should
Existing line attributesSubmit an empty attribute arrayClearing is deliberate and visible to the integration
Existing promotion codesSubmit a different listFull intended list is represented after replacement
Code that does not qualifyApply code to the current cartApplicability and total are reflected accurately
Previously qualifying basketRemove a qualifying itemAgent refreshes the promotion result and total
Cart mutation returns warningsInspect responseWarning meaning is handled rather than ignored

These are acceptance tests, not results from a vendor comparison. Use test products and known promotion rules so expected outcomes can be established before the agent runs.

The shipping and tax guide adds destination and delivery choices to this sequence. The final approved amount should be based on the current offer, not a remembered product price plus an old discount.

Verify webhook authenticity before updating business state

Order and fulfillment events can inform merchant systems after the conversational interaction ends. The receiver must establish that a delivery is authentic before it changes internal state.

Shopify's delivery verification documentation specifies HMAC verification using the raw request body. It also distinguishes the delivery identifier, X-Shopify-Webhook-Id, from X-Shopify-Event-Id, which correlates deliveries from the same merchant action across subscriptions. Use the identifier appropriate to the task rather than treating every ID as an order ID.

This distinction is operationally useful. Delivery deduplication prevents a repeated delivery from reapplying a side effect. Event correlation helps explain why more than one subscription reported the same underlying action. Neither alone tells finance whether two order records represent the same commercial purchase.

Define the scope of each idempotency record. Include the merchant or account boundary where relevant so unrelated stores cannot collide. Retain the provider event and resource identifiers needed for investigation without storing unnecessary customer details in general logs.

Separate receiving, processing and reconciling

The same Shopify guidance recommends idempotent processing, quick acknowledgment and queueing for bursts. It notes that reconciliation jobs can retrieve information missed by webhook processing. Build the receiver around recoverable state rather than a single request handler that performs every downstream action inline.

A practical design records authenticated receipt durably, then tracks processing status and any failed downstream step. Do not mark the business side effect complete merely because the incoming delivery was acknowledged. An acknowledgment means the receiver accepted the delivery, not that fulfillment or reporting finished.

The exact implementation depends on the integration, but the acceptance criteria can remain clear:

Receiver conditionDesired behavior to verifyEvidence
Invalid signatureReject before business processingRejection record without a commercial side effect
Repeated deliveryDo not repeat a completed side effectDelivery ID and processing result
Two subscriptions report one eventCorrelate without confusing deliveries with ordersEvent ID, subscription context and resource ID
Worker fails after receiptPreserve work for controlled recoveryDurable receipt and failed processing status
Downstream system is unavailableInvestigate or retry under an explicit policyAttempt history and responsible owner
An event was missedReconcile against authoritative resourcesDifference report and corrective action

These checks do not require every provider to use identical headers or delivery semantics. If you also process payment-provider webhooks, implement their documented verification and event model separately.

Join the evidence without overstating the outcome

Maintain a trace from the selected variant to the cart, checkout and merchant order where those records exist. Payment and fulfillment records may arrive through separate systems. Join them deliberately rather than inferring an order from the final assistant message.

A useful operations view distinguishes cart changes, accepted checkout, payment state, order state and receiver failures. That lets the team answer whether the customer saw the correct promotion and whether the merchant recorded the resulting purchase.

Use the commerce-agent recovery guide for uncertainty around completion. Webhook replay is not permission to create a new checkout or charge. It is a way to recover processing of evidence under the applicable integration contract.

Before expanding the pilot, run the sequence and receiver tests with engineering, merchandising and operations. Save sanitized inputs, expected outcomes and merchant records. If you need to connect these boundaries, review agentic checkout and book a workflow review with your variant model, promotion setup and event consumers.

FAQ

Sources

  1. 1.Shopify's cartLinesUpdate reference - shopify.dev
  2. 2.Shopify's cartDiscountCodesUpdate - shopify.dev
  3. 3.Shopify's delivery verification documentation - shopify.dev

Put this into practice

Walk through your shopper journey, integration requirements and the results you want to measure with Tru Commerce.

Choose a time after the form · 30 minutes · no card

Continue reading