Public API v2: Rules & publishing
From a write to the storefront
Section titled “From a write to the storefront”- Write.
POST,PUT,PATCH,DELETEand bulk requests save to the app. You see the result in the app at once. - Publish.
POST /api/v2/<module>/rules/uploadsends every enabled rule of the module to the storefront, as the Upload button of the app does. Disabled rules are not sent. - Live. Shoppers see the rules after the upload.
Two modules differ: Auto Tag rules apply as soon as they are saved and have no upload; Discount Code codes work at checkout as soon as they are saved, and the upload only refreshes the code box and share page. See Upload.
Which rule applies
Section titled “Which rule applies”- A rule applies to a shopper and a product when its customer, product, market and schedule conditions all match.
- When several rules of a module match, the one with the lowest
priorityapplies (0 is the highest priority). If the priorities are equal, the oldest rule applies. - Priority only ranks rules within one module. Rules of different modules work side by side.
- A
disabledrule never applies; use it to prepare a rule before it goes live.
Customers, products, markets and schedule
Section titled “Customers, products, markets and schedule”- Customers:
apply_tochooses who is included;exclude_fromleaves some of them out, and an excluded customer stays out even when included. - Products:
product_condition_typechooses the products;exc_product_typeleaves some of them out. - Markets:
market_condition_type: by_idslimits the rule to the listed Shopify markets. - Schedule:
start_atandend_atare UTC. Leavestart_atout to start at once andend_atout to never end. - Details and the modules that have each condition: Common objects.
Replacing and deleting
Section titled “Replacing and deleting”PUTreplaces the whole rule: send every field you want to keep. Optional fields left out go back to their defaults, and lists or table rows left out are removed.- A deleted rule cannot be read or changed again: its id answers
404. - The API never changes a rule you did not name in the request.
Test without affecting shoppers
Section titled “Test without affecting shoppers”- Create rules
disabled, read them back, and enable them when they are right. - Until you upload, writes do not reach the storefront (except Auto Tag and Discount Code codes).
- Use a development store with the app installed to try uploads.
- Public API v2: Authentication & keysCreate Public API v2 keys with per-module permissions, send them with every request, and keep them safe.
- Public API v2: Auto TagRules that tag customers and orders, add notes or mark a customer tax exempt when an event happens.
- Public API v2: Buy X Get YBuy X Get Y offers: what the customer buys, what they get, and the discount on it.
- Public API v2: Bulk & idempotencyCreate, replace or delete up to 250 rules in one Public API v2 request, and retry POST requests safely.