The abandoned cart plugin’s REST API
Zypento Abandoned Cart Recovery adds six routes to your store’s WordPress REST API. This page lists each one, who calls it, what it checks before doing anything, and what it does.
The six routes
All six are under /wp-json/zypento/v1/ on your store. Zypento’s servers call two of them. Your WordPress admin screens call three, and your checkout page calls one.
| Route | Called by | Who may call it |
|---|---|---|
POST /coupon | Zypento | A request signed with your API key |
POST /mail | Zypento | A request signed with your API key |
POST /checkout-email-captured | Your checkout page | Any visitor, with the checkout page’s nonce, and only while email capture is on |
GET /dashboard-stats | The plugin’s dashboard | An administrator (manage_options) |
POST /admin-settings | Zypento › Connection | An administrator, with the plugin’s admin nonce |
POST /cart-recovery-settings | Zypento › Privacy & capture | An administrator, with the plugin’s cart recovery nonce |
None of the routes ever returns your API key, and none reads your orders, customers or products. The only things they create are a coupon and an email, and the only settings they change are the plugin’s own.
How Zypento signs a request
Zypento calls /coupon and /mail from its servers, with no WordPress login. Each request is signed with the API key you pasted into Zypento › Connection in WordPress, and the key itself is never sent.
Content-Type: application/json
X-Zypento-Timestamp: 1795089600
X-Zypento-Signature: 6f1c…e2a9
The timestamp is the time of the request in Unix seconds. The signature is the hex HMAC-SHA256 of the timestamp, a line break and the raw request body, keyed with your API key:
signature = hex( HMAC-SHA256( api_key, timestamp + "\n" + body ) )
The store refuses the request unless all four of these hold:
- The plugin is connected: a business key and an API key are saved in Zypento › Connection.
- The timestamp is within five minutes of the store’s clock, so a captured request can’t be replayed later.
- The signature matches. It is compared in constant time.
- The
businessfield in the body is the business key saved in the plugin.
A refused request gets 401 before the route does anything:
{ "code": "zypento_unsigned", "message": "Not signed by Zypento.", "data": { "status": 401 } }
POST /coupon
Creates the discount for one recovery email.
- Address
/wp-json/zypento/v1/coupon- Called by
- Zypento, when a recovery email offers a discount.
- Permission
- A signed request. No WordPress login.
Request
{
"business": "your business key",
"nudge": "the recovery email's 32-character key",
"email": "shopper@example.com",
"discount": { "type": "percent", "amount": 10, "max": 20 },
"subtotal": 86.50,
"days": 7
}
| Field | What it is |
|---|---|
business | Your business key. It must match the one saved in the plugin. |
nudge | The key of the recovery email the coupon is for: 32 letters and digits. One coupon per key. |
email | The shopper’s address. Only this address can use the coupon. |
discount | type is percent or fixed. amount is the percentage or the amount off. max caps a percentage, and 0 means no cap. |
subtotal | The cart’s subtotal, used to work out a capped percentage. |
days | How many days the coupon lasts, from 1 to 30. Zypento sends 7. |
What it does
- If a coupon was already made for this
nudge, it returns that coupon’s code and creates nothing, so a retried request gets the same coupon. - Otherwise it creates one WooCommerce coupon, coded
ZYPfollowed by ten capital letters and digits. The coupon:- can be used once in total;
- works only for the shopper’s email address;
- is set to individual use, so it can’t be combined with another coupon;
- expires after
daysdays; - is described as “Zypento cart recovery” and carries the email’s key in its
_zypento_nudgemeta field.
- The discount takes one of three shapes:
- a percentage from 1 to 90, with no cap, becomes a percentage discount;
- a percentage with a cap becomes a fixed amount off the cart: the percentage of
subtotal, but no more thanmax; - a fixed amount above 0 becomes a fixed amount off the cart.
- It changes nothing else in the store.
Responses
| Status | Body | When |
|---|---|---|
| 200 | { "result": true, "code": "ZYP…" } | The coupon was created, or had already been made for this email. |
| 400 | "reason": "bad_request" | nudge or email isn’t valid. |
| 400 | "reason": "bad_discount" | The discount isn’t one of the three shapes, or a capped percentage comes to nothing. |
| 401 | "code": "zypento_unsigned" | The request failed the signature check. |
| 500 | "reason": "save_failed" | WooCommerce couldn’t save the coupon. |
| 503 | "reason": "woocommerce_missing" | WooCommerce isn’t active. |
POST /mail
Has your store send one recovery email.
- Address
/wp-json/zypento/v1/mail- Called by
- Zypento, only for a business with no email gateway set up in Zypento. With a gateway, Zypento sends the email itself and never calls this route.
- Permission
- A signed request, checked the same way as
/coupon. No WordPress login.
Request
{
"business": "your business key",
"nudge": "the recovery email's 32-character key",
"to": "shopper@example.com",
"subject": "You left something in your cart",
"html": "<html>…</html>",
"text": "…"
}
| Field | What it is |
|---|---|
business | Your business key. It must match the one saved in the plugin. |
nudge | The recovery email’s key: 32 letters and digits. Each key is sent once. |
to | One email address. |
subject | Required. HTML tags are removed, and line breaks become spaces. |
html | Required. The email Zypento wrote, with its unsubscribe link already in it. At most 256 KB. |
text | A plain-text copy. The plugin sends the HTML version. |
What it does
- If this
nudgewas sent in the last 14 days, it answers that the email was sent and sends nothing again. - If the store has already sent 300 recovery emails in the current hour (UTC), it refuses with
429, and Zypento tries again later. - Otherwise it sends the email to
tothrough WooCommerce’s mailer. The sender’s name and address are the ones set under WooCommerce › Settings › Emails, and the email goes through any SMTP plugin the site uses. If WooCommerce isn’t loaded, it useswp_mail(). - A request can’t add headers, attachments or more recipients.
- “Sent” means WordPress’s mailer accepted the email. The store sends Zypento no delivery reports.
Responses
| Status | Body | When |
|---|---|---|
| 200 | { "result": true } | The email was handed to the mailer. |
| 200 | { "result": true, "already": true } | This email was sent before. Nothing was sent again. |
| 400 | "reason": "bad_request" | A field is missing or isn’t valid, or html is over 256 KB. |
| 401 | "code": "zypento_unsigned" | The request failed the signature check. |
| 429 | "reason": "rate_limited" | 300 emails have been sent this hour. |
| 502 | "reason": "mail_failed" | WordPress’s mailer refused the email. |
POST /checkout-email-captured
Passes on the email address a shopper types at checkout.
- Address
/wp-json/zypento/v1/checkout-email-captured- Called by
- The plugin’s script on your checkout page, as the shopper fills in their billing email and name.
- Permission
- No login is needed, because guests check out without an account. The request must carry the nonce the plugin prints on the checkout page. While “Collect shopper email at checkout” (Zypento › Privacy & capture) is off, every request is refused, and the checkout page doesn’t load the script.
Request
Form fields:
email: required, and must be a valid address.first_nameandlast_name: optional.nonce: required.
The cart is the one named by the shopper’s zypento_ac_session_id cookie, which the plugin sets when something is added to the cart.
What it does
- Passes the email address, and the names if given, to Zypento for that cart. It doesn’t wait for Zypento’s answer.
- Sets them as the billing email and names on the shopper’s WooCommerce session.
- Returns no data. It reads nothing back.
Responses
| Status | Body | When |
|---|---|---|
| 200 | { "result": true } | Passed on. |
| 200 | { "result": false, "reason": "no_session" } | The request has no cart cookie. |
| 400 | WordPress’s rest_missing_callback_param or rest_invalid_param | The email or the nonce is missing or isn’t valid. |
| 403 | "reason": "capture_disabled" | Email capture is off. |
GET /dashboard-stats
Shows your cart recovery figures on the plugin’s dashboard.
- Address
/wp-json/zypento/v1/dashboard-stats- Called by
- The plugin’s dashboard in wp-admin.
- Permission
- A signed-in user with the
manage_optionscapability, which by default means an administrator.
What it does
- Takes no parameters, and only reads.
- If the plugin isn’t connected, it answers
{ "result": false, "reason": "not_connected" }. - Otherwise your server asks Zypento for the store’s figures, using the saved keys, and returns them. The figures are the last 7 days’ revenue and recoveries, carts tracked in the last 24 hours and in total, the recovery rate, and how carts divide by status.
- A good answer is kept for five minutes and returned with
"cached": truein the meantime. A failed one isn’t kept: it answers"reason": "platform_unreachable", or passes on Zypento’s refusal. - The browser never sees your API key: the call to Zypento is made by your server.
POST /admin-settings
Saves your connection to Zypento.
- Address
/wp-json/zypento/v1/admin-settings- Called by
- The Zypento › Connection screen in wp-admin.
- Permission
- A signed-in user with
manage_options, and the plugin’s admin nonce in thenoncefield. The route also acceptsGET, with the same checks.
Request
value: a JSON string,{ "business_id": "…", "api_key": "…" }.action: required by the route. Its value isn’t used.nonce: required.
What it does
- Saves the business key and the API key, with any HTML tags removed, in place of the ones saved before.
- Both are required. If either is missing, nothing is saved, and the answer says which is missing.
- It never returns either key. The answer is
"result": truewhen the keys were saved.
POST /cart-recovery-settings
Switches email capture at checkout on or off.
- Address
/wp-json/zypento/v1/cart-recovery-settings- Called by
- The Zypento › Privacy & capture screen in wp-admin.
- Permission
- A signed-in user with
manage_options, and the plugin’s cart recovery nonce in thenoncefield.
Request
value: a JSON string,{ "collect_checkout_email": "1" }to switch capture on, or"0"to switch it off.nonce: required.
What it does
- Sets “Collect shopper email at checkout”, which is off until you switch it on. It changes no other setting, and ignores anything else in
value. - Answers
{ "result": true, "data": { "collect_checkout_email": "1" } }with the setting as saved, or"reason": "invalid_payload"whenvalueisn’t JSON. - While capture is off, the email and name a guest types at checkout are never sent to Zypento, and
/checkout-email-capturedrefuses every request.
The recovery link
Not a REST route, but it is the other way into the plugin from outside. The link in a recovery email opens your store with two parameters:
https://your-store.example/?zypento_ac_t=<token>&zypento_ac_code=<coupon code, or none>
When a page loads with zypento_ac_t, the plugin:
- ignores a token that isn’t 32 letters and digits;
- sets a
zypento_ac_couponcookie for 30 days, so the thank-you page knows the order came through a recovery link; - asks Zypento which cart the token belongs to. Zypento looks for it only among your store’s own emails;
- takes over that cart’s session, so the order counts as that cart’s;
- if the shopper’s cart is empty, adds the cart’s products and quantities, so the link works on any device;
- applies the coupon, and sends the shopper to checkout.
When a request is refused
Zypento shows why a recovery email wasn’t sent in each cart’s History, on the Cart recovery › Recoveries tab.
The store refused the request (401)
The signature didn’t check out. The business key and API key in Zypento › Connection must be this business’s current keys, copied from the Businesses screen in Zypento.
The store’s clock must also be within five minutes of the real time. If a firewall or proxy in front of WordPress removes headers it doesn’t know, let the X-Zypento-Timestamp and X-Zypento-Signature headers through.
The cart plugin can’t create discounts or send email (404)
The store answered as if the route doesn’t exist. Either the plugin is older than version 2.0.0, or something on the site blocks the REST API for visitors who aren’t signed in, which some security plugins do. Update the plugin, or allow /wp-json/zypento/v1/coupon and /wp-json/zypento/v1/mail.
The store’s address isn’t a public https site
Zypento calls the store only at a public https address. Set the business’s URL in Zypento to the store’s own address, starting with https://.
Some emails go out an hour late
A store sends at most 300 recovery emails an hour through /mail. Emails over that are refused with 429, and Zypento tries them again later. With an email gateway set up in Zypento, the store sends nothing and this limit doesn’t apply.
This page describes version 2.0.0 of the plugin. To set it up, see cart recovery for online stores.