How to Auto-Apply Volume Discounts to Shopify B2B Orders

Build a Spojit workflow that fires on every Shopify order, lets an AI agent judge line-item quantities against your tier rules, creates a matching discount code, and tells your sales team in Slack.

What This Integration Does

Wholesale and B2B buyers expect their pricing to reflect how much they order, but Shopify does not apply quantity-based volume pricing out of the box for every checkout. This workflow closes that gap. Each time an order comes in, Spojit reads the line items, decides which volume tier the order qualifies for, and creates a Shopify discount code sized to that tier. Your sales team gets a Slack message with the order number, the tier reached, and the code that was generated, so they can pass it to the customer for their next order or apply it as a manual adjustment. The judgement of "which tier does this order hit" is handled by an Agent-mode Connector node, so you can express your tier rules in plain language instead of hand-coding every threshold.

The workflow is event-driven. A Shopify Webhook trigger starts a run the moment an order is created, and Spojit returns a fast acknowledgement to Shopify while the rest of the steps run asynchronously. Data flows from the trigger body (the order and its line items) into a Connector node running in Agent mode, which returns a structured tier decision, then into a Direct-mode Connector node that calls Shopify create-discount, and finally into a Slack send-message step. Because each run creates a uniquely coded discount, re-running on the same order produces a new code rather than overwriting an existing one, so enable webhook deduplication (covered below) if you want exactly-once behaviour per order.

Prerequisites

  • A Shopify connection with permission to read orders and create discounts. See the Shopify connector reference for setup.
  • A Slack connection authorised to post in the channel your sales team watches. See the Slack connector reference.
  • A Shopify signing connection (scheme: Shopify) so the Webhook trigger can verify incoming order events. See Setting Up a Webhook Connection.
  • Your written volume tier rules, for example: 50 to 99 units = 5% off, 100 to 249 units = 10% off, 250+ units = 15% off. You will paste these into the agent prompt.

Step 1: Start with a Shopify Webhook trigger

Add a Trigger node and set its type to Webhook. Choose your Shopify signing connection so incoming requests are verified by HMAC. Copy the generated workflow URL and register it in Shopify as an orders/create webhook so a run starts the instant an order is placed. The trigger output is the parsed Shopify order JSON, available downstream as {{ input }}, including {{ input.line_items }}, {{ input.order_number }}, and {{ input.email }}. The trigger returns 202 with an executionId to Shopify immediately, so the discount logic never blocks the checkout.

Step 2: Reduce the line items to a quantity total

Add a Connector node in Direct mode on the array connector and pick the pluck tool to extract just the quantities from {{ input.line_items }} using the field quantity. Then add a Connector node on the math connector using the sum tool to total them. Store the result so later steps can reference it as {{ totalUnits }}. This keeps the agent prompt small and cheap by handing the AI a single number plus the per-line breakdown rather than asking it to add quantities itself.

// array pluck input
{
  "array": {{ input.line_items }},
  "path": "quantity"
}

// math sum input
{
  "values": {{ pluck_result }}
}

Step 3: Let an AI agent decide the volume tier

Add a Connector node on the shopify connector and switch it to Agent mode. Agent mode lets the agent reason over the order and choose how to respond, and its Response Schema forces a clean JSON result you can branch on. Paste your tier rules into the prompt and reference the totalled quantity and order context with variables.

Order #{{ input.order_number }} has a total of {{ totalUnits }} units
across these line items: {{ input.line_items }}.

Apply these volume tiers (highest matching tier wins):
- 50 to 99 units: 5% off (code prefix VOL5)
- 100 to 249 units: 10% off (code prefix VOL10)
- 250 or more units: 15% off (code prefix VOL15)
- Fewer than 50 units: no discount

Return the tier reached, the discount percentage as a decimal,
and a suggested human-readable title.

Set a Response Schema so the output is reliable:

{
  "type": "object",
  "properties": {
    "qualifies": { "type": "boolean" },
    "tierLabel": { "type": "string" },
    "percentDecimal": { "type": "number" },
    "discountTitle": { "type": "string" }
  },
  "required": ["qualifies", "tierLabel", "percentDecimal", "discountTitle"]
}

Store the result as {{ tier }}. You can scaffold this entire node by asking Miraxa: "Add a Connector node on the shopify connector in Agent mode that decides a volume discount tier and returns structured JSON."

Step 4: Skip orders that do not qualify

Add a Condition node that checks whether {{ tier.qualifies }} is true. Route the false branch to a Response-free dead end (no further nodes) so small orders quietly finish, and route the true branch into the discount step. This avoids creating empty or 0% codes and keeps your Shopify discount list clean.

Step 5: Create the matching Shopify discount

On the true branch, add a Connector node in Direct mode on the shopify connector and pick the create-discount tool. Map the fields from the agent decision. Generate a unique code by appending the order number to the tier prefix so each order gets its own code. Set type to percentage and pass value as the decimal from the agent (for example 0.1 for 10%). Set appliesOncePerCustomer to true and an optional usageLimit so the code cannot be over-redeemed.

{
  "title": "{{ tier.discountTitle }} - Order {{ input.order_number }}",
  "code": "{{ tier.tierLabel }}-{{ input.order_number }}",
  "type": "percentage",
  "value": {{ tier.percentDecimal }},
  "appliesOncePerCustomer": true,
  "usageLimit": 1
}

Store the result as {{ discount }} for the notification step.

Step 6: Notify sales in Slack

Add a Connector node in Direct mode on the slack connector and pick the send-message tool. Set the target channel and compose a templated message that names the order, the tier reached, and the generated code so a salesperson can act on it.

{
  "channel": "#b2b-sales",
  "text": "Volume discount ready for order #{{ input.order_number }} ({{ tier.tierLabel }}, {{ tier.discountTitle }}). Code: {{ tier.tierLabel }}-{{ input.order_number }}. Customer: {{ input.email }}."
}

If you would rather email the customer the code directly, swap or add a Send Email node and template the body the same way; note external recipients must be on your org allowlist under Settings > General > Email recipients.

Tips

  • Keep the Agent-mode prompt tight: pass the pre-summed {{ totalUnits }} so the AI only judges the tier rather than doing arithmetic, which lowers AI credit usage per run.
  • Use a distinct code prefix per tier (for example VOL5, VOL10, VOL15) so your finance team can filter redemptions by tier in Shopify reporting.
  • Set an endsAt on create-discount (ISO 8601) if these codes should expire, so stale wholesale discounts do not linger.
  • Ask Miraxa "Why did my last run fail?" on the run that errored; it reads the execution context and points you at the failing node.

Common Pitfalls

  • Shopify sends a separate webhook for nearly every order event. Subscribe only to orders/create (not update events) or you will generate duplicate codes for the same order.
  • Webhook replays and retries can re-fire the same order. Turn on the opt-in event-id deduplication on the Webhook trigger so a retried delivery does not create a second discount.
  • The value field on create-discount expects a decimal for percentage discounts (0.1 means 10%, not 10). Make your Response Schema enforce percentDecimal and validate the agent never returns a whole number.
  • Discount codes must be unique in Shopify. If you reuse a fixed code across orders the call fails, so always include the order number (or another unique token) in code.

Testing

Before pointing real traffic at this, place one low-quantity test order and one high-quantity test order in a development or draft context. Run the workflow with each and confirm the small order takes the false branch (no code created) while the large order produces a discount whose percentage matches the tier you expect. Inspect the run in your execution history to verify the agent returned valid JSON and that the create-discount output contains the new code, then check the Slack channel received the message before you register the live orders/create webhook in Shopify.

Learn More

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.