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 theOPTIONSrequest for theContent-TypeandX-checkout-session-tokenheaders.
Steps
Start a rule
Open Rules → New checkout rule. Add a Title. Conditions are optional. Without them, the API is called on every checkout.
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.
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:
| Field | Holds |
|---|---|
deliveryAddress | Shipping address fields, incl. zip, countryCode |
email, customer | Buyer’s email, logged-in customer |
cart.cost.totalAmount | Subtotal and currency |
cart.lines | Lines with quantity and product |
cart.deliveryGroups | Delivery options |
cart.attributes, cart.metafields | Cart attributes and metafields |
appliedGiftCards, selectedPaymentOptions | Gift cards, chosen payment |
discountsAllocations, productDiscounts | Discounts |
Input Query also takes a plain list, like email, customer. If it can’t be read, everything is sent.
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" }
]
}
actionsis required, even if empty. Missing it means nothing blocks.- Each
errorsentry blocks checkout.targetputs it next to a field:$.cart.buyerIdentity.email,$.cart.buyerIdentity.phone, or$.cart.deliveryGroups[0].deliveryAddress.+ a field likezip. - The HTTP status code is ignored.
Actions your API can return
Each is { "action": "<name>", "value": { … } }.
action | value | Does |
|---|---|---|
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_message | any | Saves 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
OPTIONSrequest in the network tab means CORS is missing. Otherwise check the rule is Active. - Errors don’t block: include an
actionsarray, 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.