Skip to content
On this page
How-to Checkout rules 3 min read Updated Sep 28, 2026

Validate checkout with your own API

In short

Add a Validate Via API action to a checkout rule and enter your API URL. Checkout data is POSTed as JSON to that URL, and each error your API returns blocks checkout and shows its message.

✓ Applies to

  • Deluxe plan only (checkout rules aren't included in Advanced)
  • Shopify Plus checkout, with the Rules Executor block added
  • Developers who run an HTTPS endpoint that accepts cross-origin POST requests

✕ Doesn't apply to

  • Server-side order validation after payment. The call happens in the buyer's browser during checkout
  • Custom request headers. The API Headers field isn't sent with the request

Before you start

  • Add the Rules Executor and allow it to block checkout progress. How.
  • Get an HTTPS API URL from your developer that follows the format below.
  • The endpoint needs CORS (permission for browser calls): reply with Access-Control-Allow-Origin: * and handle the OPTIONS request for the Content-Type and X-checkout-session-token headers.

Steps

1

Start a rule

Open Rules → New checkout rule. Add a Title. Conditions are optional. Without them, the API is called on every checkout.

2

Add Validate Via API

Click Add Action → Validate Via API. Paste the API URL. In Input Query, list only the fields to send. Leave it empty to send everything.

3

Turn it on

Set Status to Active and click Save.

The request

A POST with Content-Type: application/json and, when Shopify provides one, X-checkout-session-token. The body is checkout data as JSON:

FieldHolds
deliveryAddressShipping address fields, incl. zip, countryCode
email, customerBuyer’s email, logged-in customer
cart.cost.totalAmountSubtotal and currency
cart.linesLines with quantity and product
cart.deliveryGroupsDelivery options
cart.attributes, cart.metafieldsCart attributes and metafields
appliedGiftCards, selectedPaymentOptionsGift cards, chosen payment
discountsAllocations, productDiscountsDiscounts

Input Query also takes a plain list, like email, customer. If it can’t be read, everything is sent.

i

The session token is a hint, not proof. You can’t verify it with your own credentials, so check every field.

The response

{
  "actions": [],
  "errors": [
    { "message": "We can't deliver to this postcode.",
      "target": "$.cart.deliveryGroups[0].deliveryAddress.zip" }
  ]
}
  • actions is required, even if empty. Missing it means nothing blocks.
  • Each errors entry blocks checkout. target puts it next to a field: $.cart.buyerIdentity.email, $.cart.buyerIdentity.phone, or $.cart.deliveryGroups[0].deliveryAddress. + a field like zip.
  • The HTTP status code is ignored.

Actions your API can return

Each is { "action": "<name>", "value": { … } }.

actionvalueDoes
hide{ "name": "Cash on Delivery" }Hides payment methods containing the name
hide_all_payment_except{ "name": "Card" }Hides all others
hide_all_payment_methods{}Hides all
rename{ "currentName": "COD", "newName": "Pay on delivery" }Renames
move_to_position{ "name": "COD", "position": "1" }Moves (1 = first)
set_messageanySaves to cart attribute _checkout_ninja_message, not shown

Aliases: hide_payment, hide_payment_method, rename_payment, move_payment_to_position.

!

An unknown action name breaks all payment hiding, including your Hide payment method rules.

Good to know

  • Responses are cached for 5 minutes for the same data. Use Input Query to avoid extra calls.
  • The call runs in the buyer’s browser, so the endpoint is public and visible.
  • API Headers is saved but not sent.
  • No timeout: checkout waits while your API answers. Keep it fast.
  • If the API fails or returns bad JSON, checkout isn’t blocked.

Check it works

Return a fixed error for one test postcode. Enter it at checkout: you’re blocked. Enter another: you can continue.

Not working?

  • API never called: a failed OPTIONS request in the network tab means CORS is missing. Otherwise check the rule is Active.
  • Errors don’t block: include an actions array, and allow the Rules Executor to block. Fix.
  • Stale data: that’s the 5-minute cache. Change the test data or start a new checkout.

Frequently asked

When is my API called? +

Whenever the rule's conditions match and the checkout data you send has changed. The Rules Executor re-runs rules each time the checkout changes, and caches each response for 5 minutes.

What happens if my API is down? +

The whole rules run fails for that update, so no rule errors block the buyer and checkout can continue. Other rule actions from that same run are skipped too.

Can I send an API key in a header? +

Not at the moment. The API Headers field is saved but not sent. The request carries only Content-Type and X-checkout-session-token.

Does the HTTP status code matter? +

No. The executor reads the JSON body whatever the status code, so a 500 response with an errors array still blocks checkout.

Related guides

Still stuck? Open the app and use Support to chat with the team, or contact us. Don't have the app yet? Install Checkout Ninja.