> ## Documentation Index
> Fetch the complete documentation index at: https://docs.supercycle.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a workflow

> Build an automation from a Supercycle trigger and action in Shopify Flow

A workflow in [Shopify Flow](https://help.shopify.com/en/manual/shopify-flow) starts with a trigger, checks conditions, and runs actions. Supercycle adds its own triggers and actions to that list, so a return, a cycle, a membership, or a failed payment can drive the work. The full list of what Supercycle exposes is on [Automation overview](/documentation/manage/automation/automation).

***

## Build a workflow

<Steps>
  <Step title="Open Shopify Flow">
    Go to <Icon icon="shopify" iconType="solid" /> **[Flow](https://admin.shopify.com/apps/flow)** and select **Create workflow**.
  </Step>

  <Step title="Choose a trigger">
    Search for `Supercycle` and pick the event that starts the workflow, such as **Return created**, **Cycle updated**, **Membership canceled**, or **Payment collection failed**.
  </Step>

  <Step title="Add conditions and actions">
    Add conditions to decide when the workflow acts, loops to walk through a list such as the cycles on a return, and actions to do the work.
  </Step>

  <Step title="Test and turn it on">
    Run Flow's test with sample data, then turn the workflow on.
  </Step>
</Steps>

<Tip>
  Name workflows after what they do, for example `Pause subscription on return`, so they're easy to find in a long list.
</Tip>

***

## Pause a subscription on return

Pause a customer's subscription as soon as they start a return.

<Frame type="glass" caption="Pausing subscriptions when returns are created.">
  <iframe src="https://fast.wistia.net/embed/iframe/1kvx2zyjuz" title="Pause a subscription when a return is created in Shopify Flow" width="100%" height="400" allow="autoplay; fullscreen" frameborder="0" />
</Frame>

<Steps>
  <Step title="Add the trigger">
    Select **Return created**.
  </Step>

  <Step title="Add a loop">
    Add a **For each** loop over `returnOrder.rentals`, so each cycle in the return is handled on its own.
  </Step>

  <Step title="Add a condition">
    Add a **Condition** that checks the cycle for a subscription.

    ```text Condition theme={null}
    rentals.foreachitem.subscriptionId is not empty and exists
    ```
  </Step>

  <Step title="Add the action">
    In the **Then** branch, add **Update subscription**. Set **Subscription ID** to `{{rentals.foreachitem.subscriptionId}}` and **Status** to `paused`.
  </Step>

  <Step title="Turn the workflow on">
    Save and turn it on. Subscriptions pause as returns are created.
  </Step>
</Steps>

***

## Notify the team on a failed payment

Tell your team when a subscription payment has failed several times.

<Steps>
  <Step title="Add the trigger">
    Select **Payment collection failed**.
  </Step>

  <Step title="Add a condition">
    Check the attempt count so only repeated failures reach the team.

    ```text Condition theme={null}
    paymentCollector.failedPaymentCount is greater than or equal to 3
    ```
  </Step>

  <Step title="Add the notification">
    In the **Then** branch, add **Send internal email**. Address it to your support team, give it a subject such as `Customer payment failed 3 times`, and include `paymentCollector.lastFailedPayment.errorMessage` in the body.
  </Step>

  <Step title="Cancel the subscription (optional)">
    Add **Update subscription** after the email. Take the **Subscription ID** from `paymentCollector.subscriptionContractId` and set **Status** to `cancelled`.
  </Step>

  <Step title="Turn the workflow on">
    Save and turn it on.
  </Step>
</Steps>

***

## Resolve item conflicts on a cycle

When a cycle's allocated item is unavailable, for example because it's still out on another cycle, let Supercycle pick a fresh one.

<Steps>
  <Step title="Add the trigger">
    Select **Cycle updated**.
  </Step>

  <Step title="Add a condition">
    Check the cycle for an item or variant conflict.

    ```text Condition theme={null}
    rental.conflictLevel is equal to item or rental.conflictLevel is equal to variant
    ```
  </Step>

  <Step title="Add the action">
    In the **Then** branch, add **Re-allocate item** with **Cycle ID** set to `{{rental.id}}`.
  </Step>

  <Step title="Turn the workflow on">
    Save and turn it on. Cycles with an item conflict are re-allocated as the conflict appears.
  </Step>
</Steps>

***

## Update an item's condition after its first cycle

Downgrade an item's condition once it has been out and come back, for example from **New** to **Pre-loved**.

<Steps>
  <Step title="Add the trigger">
    Select **Cycle updated**.
  </Step>

  <Step title="Add a condition">
    Check that the cycle was received and that the item has exactly one completed cycle.

    ```text Condition theme={null}
    rental.receivedAt is not empty and rental.item.completedCycles is equal to 1
    ```
  </Step>

  <Step title="Add the action">
    In the **Then** branch, add **Update item**. Set **Item ID** to `{{rental.item.id}}` and **Condition ID** to the ID of the condition you want, such as `gid://supercycle/Condition/456`. Copy it from your [item conditions](/documentation/manage/inventory/item-conditions) settings, or from an item that already has that condition.
  </Step>

  <Step title="Turn the workflow on">
    Save and turn it on. Items move to the new condition after their first completed cycle.
  </Step>
</Steps>

***

## Workflow FAQs

<AccordionGroup>
  <Accordion title="Can a single return include more than one rental?">
    Yes. A return can cover several cycles, so walk `returnOrder.rentals` with a **For each** loop rather than acting on the first one.
  </Accordion>

  <Accordion title="Do all cycles have a subscription attached?">
    No. Check that `subscriptionId` exists in a condition before any action uses it, or the step fails on cycles without one.
  </Accordion>

  <Accordion title="How do I validate a workflow before turning it on?">
    Use Flow's test feature with sample data and confirm each branch does what you expect before the workflow runs on real orders.
  </Accordion>

  <Accordion title="How do I know my workflows are still running correctly?">
    Check the Flow dashboard for run history. It shows successful runs and the steps that errored, so a broken condition or a missing ID shows up early.
  </Accordion>
</AccordionGroup>
