Skip to Content
API ReferenceSupport automation rules

Overview

Answer new tickets automatically with a reply, a wallet refund and a close, and test rules before they act.

Automation rules answer new support tickets without anyone on your team. When a customer opens a ticket, SellApp checks your rules in order. The first switched-on rule that matches the ticket posts its reply template to the customer, can credit a refund to the customer's store wallet, and can close the ticket. Use rules for requests you always answer the same way, such as resending a download link or refunding a small first-time problem.

What a switched-on rule does

A rule acts on real tickets and real money. Read this before you switch one on.

  • A rule needs two switches. The store's support automation must be on (automation_enabled in support automation settings), and the rule itself must be switched on (is_active: true). New rules start paused. Turning either switch on lets the rule act on the next new ticket.
  • It acts without a person. The reply is posted as a message from your store and the customer is notified. A refund is credited to the customer's store wallet straight away. A close ends the ticket with the action_close_outcome you chose, and the customer is notified of that too.
  • It acts only on new tickets. Rules run when a customer opens a ticket, not on existing tickets or on replies.
  • Each ticket gets at most one rule. Rules are checked from the lowest priority up. The first switched-on rule that matches answers the ticket, and no rule after it runs for that ticket. Conditions you leave empty match every ticket, so a rule without conditions answers every new ticket that reaches it.
  • Paused and archived rules never run.

Refunds need a daily refund cap

A rule refunds when it has an action_refund_kind: full refunds what is left to refund on the ticket's purchased item, partial a share of it in hundredths of a percent (action_refund_percent_basis: 5000 is 50%), fixed an amount in USD cents (action_refund_fixed_cents: 500 is $5.00). The money is credited to the customer's store wallet.

While support automation is on, a refunding rule can run only when the store has a daily refund cap, daily_refund_cap_cents in the settings (5000 means $50.00). SellApp refuses, with 422, anything that would leave a switched-on refunding rule without a cap: switching such a rule on, creating it switched on, adding a refund to a switched-on rule, turning automation on, or removing the cap.

Before each automatic refund, SellApp adds up the automatic refunds credited since the start of the day, leaving out reversed ones. If this refund would take that total over the cap, the rule does nothing for the ticket: no refund, no reply and no close. The refund is not reduced to fit. The ticket stays open for your team, and no other rule is tried for it.

A rule also does nothing for a ticket when its refund cannot be made: the ticket has no one-off purchased item (no item, or a subscription), nothing is left to refund, the rule's own cap is used up, or the wallet credit fails, for example because a fixed amount is more than is left to refund. The ticket stays open for your team.

action_refund_cap_cents is a second, per-order limit on the rule: the most it refunds automatically for one order, counted across every ticket about that order. A refund is reduced to what is left under it.

When a rule's template is paused

A rule keeps its response_template_id when that template is later paused (is_active: false) or taken off automation (supports_auto_respond: false). What happens next depends on the rule:

  • A rule that only replies sends nothing, and the ticket goes on to the next rule.
  • A rule that also refunds or closes still takes the tickets it matches, but does nothing for them: no reply, no refund, no close. No rule after it handles those tickets either.

Resume the template, or point the rule at another active template offered to automation, to make the rule act again.

Test a rule with the dry run

Dry run shows what your rules would do with one of your tickets if it were opened now: which rule would answer it, the reply text, the refund in USD cents and the close outcome. Nothing is sent, refunded, closed or recorded.

Two limits matter:

  • Only switched-on rules take part, in their current order. A paused rule does not show up until you switch it on, so the last check happens right after you switch it on. Pause it again at once if the result is wrong.
  • For a refund, it checks only that the ticket's order is paid and not already refunded. It does not check the daily refund cap, the rule's per-order cap, or whether anything is left to refund. A would_execute: true result can still end with the rule doing nothing when it runs.

With support automation off, the dry run answers matched: false with skip_reason: auto_respond_disabled. When a refund rule matches a ticket whose order is not paid or was already refunded, it answers would_execute: false with skip_reason: refund_unavailable.

Worked example: a refund rule from start to finish

This example sets up a rule for customers whose download link expired: it refunds half of an item worth up to $50.00 to customers who have had no support refund before, replies with the refund note and closes the ticket. It uses ticket 4821, opened by maya.chen@example.com about the Design kit ($19.99) with the store reason download-link-expired from support reasons.

Set your credentials and store with the quickstart. The commands need jq. Steps 2 and 3 change nothing customers see. From step 5 on, the rule refunds real money on new tickets.

1. Turn automation on with a daily refund cap. Read the settings first. If active_rules_count is above 0, those rules start answering new tickets as soon as automation is on.

Read the settings
curl --fail-with-body \
  --url "${SELLAPP_API_BASE_URL}/v2/support-automation-settings" \
  --header "Authorization: Bearer ${SELLAPP_API_KEY}" \
  --header "X-STORE: ${SELLAPP_STORE}" \
  --header 'Accept: application/json'

Send back the two values you read as the expected pair, so the change is refused if someone else changed them in the meantime. This sets a $50.00 cap and turns automation on:

Set a $50.00 daily cap and turn automation on
curl --fail-with-body --request PATCH \
  --url "${SELLAPP_API_BASE_URL}/v2/support-automation-settings" \
  --header "Authorization: Bearer ${SELLAPP_API_KEY}" \
  --header "X-STORE: ${SELLAPP_STORE}" \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"automation_enabled":true,"daily_refund_cap_cents":5000,"expected_automation_enabled":false,"expected_daily_refund_cap_cents":null}'

The response shows "automation_enabled": true and "daily_refund_cap_cents": 5000.

2. Create the reply template. supports_auto_respond: true lets rules send it. {refund_amount} and {wallet_balance} are filled with the refund the rule credits.

Create the template
TEMPLATE_ID="$(curl --fail-with-body --request POST \
  --url "${SELLAPP_API_BASE_URL}/v2/support-reply-templates" \
  --header "Authorization: Bearer ${SELLAPP_API_KEY}" \
  --header "X-STORE: ${SELLAPP_STORE}" \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"label":"Refund credited","body":"Hi {customer_email}, we credited {refund_amount} to your {store_name} wallet for {product_title}. Your wallet balance is now {wallet_balance}.","supports_auto_respond":true}' \
  | jq -er '.data.id')"

3. Create the rule, paused. Leaving out is_active creates it paused. Amounts are USD cents.

Create a paused rule
RULE="$(curl --fail-with-body --request POST \
  --url "${SELLAPP_API_BASE_URL}/v2/support-automation-rules" \
  --header "Authorization: Bearer ${SELLAPP_API_KEY}" \
  --header "X-STORE: ${SELLAPP_STORE}" \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data "{\"name\":\"Expired download links\",\"response_template_id\":${TEMPLATE_ID},\"match_reason_source\":\"store\",\"match_reason_code\":\"download-link-expired\",\"match_product_ids\":[120],\"match_max_order_total_cents\":5000,\"max_prior_support_refund_count\":0,\"action_refund_kind\":\"partial\",\"action_refund_percent_basis\":5000,\"action_refund_cap_cents\":1000,\"action_close_outcome\":\"refunded_partial\"}")"
RULE_ID="$(printf '%s' "$RULE" | jq -er '.data.id')"
RULE_UPDATED_AT="$(printf '%s' "$RULE" | jq -er '.data.updated_at')"
printf '%s' "$RULE" | jq '.data | {id, is_active, priority}'

The response has "is_active": false. The rule is placed after your existing rules.

4. Dry run the ticket before switching the rule on. This shows what happens to such a ticket today, before your rule takes part.

Dry run ticket 4821
curl --fail-with-body \
  --url "${SELLAPP_API_BASE_URL}/v2/support-automation-rules/dry-run?ticket_id=4821" \
  --header "Authorization: Bearer ${SELLAPP_API_KEY}" \
  --header "X-STORE: ${SELLAPP_STORE}" \
  --header 'Accept: application/json'

In a store with no other switched-on rules, the answer is "matched": false with "rule_id": null, and nothing was sent. If another rule answers, rule_id names it: reorder your rules if yours should go first.

5. Switch the rule on. Send the updated_at you read as expected_updated_at. A refunding rule is refused without it, so you have seen its refund before it goes live. From now on, new matching tickets get the refund, the reply and the close without anyone on your team.

Switch the rule on
curl --fail-with-body --request PATCH \
  --url "${SELLAPP_API_BASE_URL}/v2/support-automation-rules/${RULE_ID}/state" \
  --header "Authorization: Bearer ${SELLAPP_API_KEY}" \
  --header "X-STORE: ${SELLAPP_STORE}" \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data "{\"state\":\"active\",\"expected_updated_at\":\"${RULE_UPDATED_AT}\"}"

422 on state means automation is on without a daily refund cap: go back to step 1. 422 on expected_updated_at means the rule changed since you read it: read it again and check it.

6. Dry run again and pause if it is wrong. Repeat the request from step 4. Now the rule answers:

Dry run result, abbreviated to the decision
{
  "data": {
    "ticket_id": 4821,
    "matched": true,
    "would_execute": true,
    "rule_id": 7,
    "rule_name": "Expired download links",
    "skip_reason": null,
    "rendered_reply": "Hi maya.chen@example.com, we credited $9.99 to your Launch Lab wallet for Design kit. Your wallet balance is now $9.99.",
    "refund_amount_cents": 999,
    "close_outcome": "refunded_partial"
  }
}

Half of $19.99, rounded down to the cent, is $9.99, under the rule's $10.00 per-order cap. If the reply, the amount or the outcome is not what you want, pause the rule straight away with {"state":"paused"} on the same state endpoint, then change it.

Change, pause, archive and order rules

  • Change a rule with PATCH or PUT; both change only the fields you send. A field sent as null keeps its value. Name a field in clear to remove it, for example "clear":["action_refund"] to stop the rule refunding. Send the updated_at you read as expected_updated_at so you never overwrite a change you have not seen. A change to a switched-on rule applies to the next new ticket.
  • Switch a rule on, pause, archive or restore it with the state endpoint. A restored rule comes back on or off, as it was when it was archived.
  • Order the rules with the reorder endpoint, sending every rule that is not archived. Put narrow rules before broad ones.

A read of a rule can be sent back as a change unchanged. is_active, archived and priority are accepted only with the values the rule already has; any other value returns 422 on that field. A field a rule does not take returns 422 naming it.

Permissions

Use an API key with the support.automation ability. The key's user needs the Support Automation role in the store; owners and administrators have it. Templates are a separate resource: creating or changing one needs the ticket ability, and a template offered to automation also needs support.automation. OAuth access tokens need support:read to read rules and run the dry run, and support:write to change them. Another store's rule or ticket returns 404.

Retries

Creating a rule is not safe to repeat blindly: each request creates a new rule. If a create response is lost, list the rules before you try again. Changes, state changes and reorders give the same result when repeated with the same body, except when they carry an expected_updated_at that the first request already made stale: then read the rule again. Reads and the dry run are always safe to repeat.

Endpoints

On this page