---
description: "Learn how to implement a create return flow in the storefront."
addHowToData: true
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# How to Create a Return in the Storefront

In this document, you’ll learn how to implement a create return flow in the storefront.

## Overview

Customers may need to return items they received from an order they placed for different reasons, such as ordering an incorrect size of the item.

The Medusa backend allows automating the process of returning an item by providing the necessary mechanism that allows customers to create the return request themselves. This guide illustrates how you can implement that mechanism in your storefront.

The process of creating a return is as follows:

- Ask the customer to select the items they want to return. You can also allow customers to select the return shipping option to use to return the item.
- Create the return in the Medusa backend.

:::note

Refunding the customer is handled by admins. You can learn how to implement or use this functionality in the [Manage Returns guide](../admin/manage-returns.mdx).

:::

---

## Prerequisites

### Medusa Components

It's assumed that you already have a Medusa backend installed and set up. If not, you can follow our [quickstart guide](../../../development/backend/install.mdx) to get started.

It's also assumed you already have a storefront set up. It can be a custom storefront or one of Medusa’s storefronts. If you don’t have a storefront set up, you can install the [Next.js Starter Template](../../../starters/nextjs-medusa-starter.mdx).

### JS Client

This guide includes code snippets to send requests to your Medusa backend using Medusa’s JS Client and JavaScript’s Fetch API.

If you follow the JS Client code blocks, it’s assumed you already have [Medusa’s JS Client installed](../../../js-client/overview.md) and have [created an instance of the client](../../../js-client/overview.md#configuration).

### Medusa React

This guide also includes code snippets to send requests to your Medusa backend using Medusa React, among other methods.

If you follow the Medusa React code blocks, it's assumed you already have [Medusa React installed](../../../medusa-react/overview.mdx) and have [used MedusaProvider higher in your component tree](../../../medusa-react/overview.mdx#usage).

---

## Step 1: Collecting Return Details

When a customer wants to create a return, they must choose the items they want to return. To display the items in the order, you can retrieve the order as explained in [this guide](./retrieve-order-details.mdx). You can then display the items in an order using `order.items`, which is an array of items.

### Showing Return Shipping Options

You can optionally allow customers to choose a return shipping option that they’ll use to return the items. To show the customers the available return shipping options, send a request to the Get [Shipping Options endpoint](https://docs.medusajs.com/api/store#shipping-options_getshippingoptions):

<Tabs groupId="request-type" isCodeTabs={true}>
<TabItem value="client" label="Medusa JS Client" default>

```ts
medusa.shippingOptions.list({
  is_return: "true",
})
.then(({ shipping_options }) => {
  console.log(shipping_options.length)
})
```

</TabItem>
<TabItem value="medusa-react" label="Medusa React">

```tsx
import { useShippingOptions } from "medusa-react"

const ReturnShippingOptions = () => {
  const { 
    shipping_options, 
    isLoading, 
  } = useShippingOptions({
    is_return: "true",
  })
 
  return (
    <div>
      {isLoading && <span>Loading...</span>}
      {shipping_options?.length && 
        shipping_options?.length > 0 && (
        <ul>
          {shipping_options?.map((shipping_option) => (
            <li key={shipping_option.id}>
              {shipping_option.id}
            </li>
          ))}
        </ul>
      )}
    </div>
  )
}

export default ReturnShippingOptions
```

</TabItem>
<TabItem value="fetch" label="Fetch API">

```ts
fetch(`<BACKEND_URL>/store/shipping-options?is_return=true`, {
  credentials: "include",
})
.then((response) => response.json())
.then(({ shipping_options }) => {
  console.log(shipping_options.length)
})
```

</TabItem>
</Tabs>

This endpoint allows you to pass the `is_return` query parameter to indicate whether the shipping options should be return shipping options. You can learn about other available filters in the [API reference](https://docs.medusajs.com/api/store#shipping-options_getshippingoptions).

The request returns an array of shipping option objects.

---

## Step 2: Create Return

You can create the return by sending a request to the [Create Return endpoint](https://docs.medusajs.com/api/store#returns_postreturns):

<Tabs groupId="request-type" isCodeTabs={true}>
<TabItem value="client" label="Medusa JS Client" default>

```ts
medusa.returns.create({
  order_id,
  items: [
    {
      item_id,
      quantity: 1,
    },
  ],
  return_shipping: {
    option_id,
  },
})
.then((data) => {
  console.log(data.return.id)
})
```

</TabItem>
<TabItem value="medusa-react" label="Medusa React">

```tsx
import { useCreateReturn } from "medusa-react"

const CreateReturn = () => {
  const createReturn = useCreateReturn()
  // ...

  const handleCreate = () => {
    createReturn.mutate({
      order_id,
      items: [
        {
          item_id,
          quantity: 1,
        },
      ],
      return_shipping: {
        option_id,
      },
    })
  }

  // ...
}

export default CreateReturn
```

</TabItem>
<TabItem value="fetch" label="Fetch API">

```ts
fetch(`<BACKEND_URL>/store/returns`, {
  credentials: "include",
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    order_id,
    items: [
      {
        item_id,
        quantity: 1,
      },
    ],
    return_shipping: {
      option_id,
    },
  }),
})
.then((response) => response.json())
.then((data) => {
  console.log(data.return.id)
})
```

</TabItem>
</Tabs>

This endpoint requires the following request body parameters:

- `order_id`: a string indicating the ID of the order to create the return for.
- `items`: an array of objects, each object being an item from the order to return. Each object must have the following properties:
    - `item_id`: a string indicating the ID of the item in the order.
    - `quantity`: a number indicating the quantity to return.

You can optionally pass the `return_shipping` parameter, which is the return shipping option that the customer will use to return the item. It’s an object that has a required property `option_id`, which is a string indicating the ID of the return shipping option.

The request returns the created return as an object.

---

## See Also

- [How to manage returns as an admin](../admin/manage-returns.mdx)
- [How to implement a create swap flow in a storefront](./create-swap.mdx)
