# Advanced return abuse detection

Tracks processed returns in a rolling window and tags customers who cross configurable abuse thresholds.

Canonical URL: https://templates.jsworkflows.com/templates/advanced-return-abuse-detection/

## When to use this template

This template is built for Shopify stores using the JsWorkflows app.

Use this template when you want a ready-made workflow for this use case: Tracks processed returns in a rolling window and tags customers who cross configurable abuse thresholds.

It is designed for Shopify risk review workflows and gives you a production-ready starting point instead of building the automation from scratch.

This workflow uses the Shopify webhook trigger model and starts from the "Returns approve" trigger. It includes setup fields for merchant-facing values, so you can configure the workflow before installing it.

## Metadata

- Category: Risk
- Trigger: Returns approve
- Workflow type: Shopify webhook
- Complexity: advanced
- Usage class: growth-friendly

## Connected services

- None

## Additional Shopify scopes

- read_returns

## Setup fields

- Return count threshold (`RETURN_COUNT_THRESHOLD`)
  - Type: number
  - Storage: config
  - Required: yes
  - Description: Number of approved returns inside the rolling window required before the customer is flagged.
- Return value threshold (`RETURN_VALUE_THRESHOLD`)
  - Type: number
  - Storage: config
  - Required: yes
  - Description: Total approved returned value in shop currency required before the customer is flagged.
- Rolling window days (`ROLLING_WINDOW_DAYS`)
  - Type: number
  - Storage: config
  - Required: yes
  - Description: How many days of approved return history are kept for threshold evaluation.
- Customer risk tag (`CUSTOMER_RISK_TAG`)
  - Type: text
  - Storage: config
  - Required: yes
  - Description: Customer tag applied when the configured thresholds are crossed.
- Order risk tag (`ORDER_RISK_TAG`)
  - Type: text
  - Storage: config
  - Required: no
  - Description: Optional order tag applied to the triggering order when thresholds are crossed. Leave blank to disable order tagging.
- Metafield namespace (`METAFIELD_NAMESPACE`)
  - Type: text
  - Storage: config
  - Required: yes
  - Description: Namespace used for the customer metafield that stores the rolling return history JSON.
- Metafield key (`METAFIELD_KEY`)
  - Type: text
  - Storage: config
  - Required: yes
  - Description: Metafield key used for the customer state JSON.

## Setup guide

## Before you start

This template watches approved returns and keeps a rolling abuse history on each customer.

## How it works

- Trigger: `returns/approve`
- Each approved return is added to a rolling history stored in a customer metafield
- The workflow totals return count and returned value over the configured window
- If both thresholds are crossed, it tags the customer and can optionally tag the triggering order
- Compare-digest metafield writes are used so concurrent return approvals do not overwrite each other

## Configure in setup

- `Return count threshold`: number of approved returns required inside the rolling window
- `Return value threshold`: total approved returned value required inside the rolling window
- `Rolling window days`: how many days of return history to keep
- `Customer risk tag`: customer tag applied when thresholds are crossed
- `Order risk tag`: optional order tag applied to the triggering order; leave blank to disable
- `Metafield namespace` and `Metafield key`: where the compact JSON history is stored on the customer

## Notes

- This template is intended for operational review and risk flagging, not automatic enforcement
- The stored state lives on the customer, so the history moves with the customer record inside Shopify

