Skip to main content
Skip to main content

Returns

Queries and Mutations listed here are used to send requests to the Admin Return API Routes.

All hooks listed require user authentication.

A return can be created by a customer or an admin to return items in an order. Admins can manage these returns and change their state.

Related Guide: How to manage returns.

Mutations

useAdminReceiveReturn

This hook marks a return as received. This also updates the status of associated order, claim, or swap accordingly.

Example

import React from "react"
import { useAdminReceiveReturn } from "medusa-react"

type ReceiveReturnData = {
items: {
item_id: string
quantity: number
}[]
}

type Props = {
returnId: string
}

const Return = ({ returnId }: Props) => {
const receiveReturn = useAdminReceiveReturn(
returnId
)
// ...

const handleReceive = (data: ReceiveReturnData) => {
receiveReturn.mutate(data, {
onSuccess: ({ return: dataReturn }) => {
console.log(dataReturn.status)
}
})
}

// ...
}

export default Return

Hook Parameters

idstringRequired
The return's ID.

Mutation Function Parameters

AdminPostReturnsReturnReceiveReqAdminPostReturnsReturnReceiveReqRequired
The details of the received return.

Mutation Function Returned Data

AdminReturnsResAdminReturnsResRequired
The return's details.

useAdminCancelReturn

This hook registers a return as canceled. The return can be associated with an order, claim, or swap.

Example

import React from "react"
import { useAdminCancelReturn } from "medusa-react"

type Props = {
returnId: string
}

const Return = ({ returnId }: Props) => {
const cancelReturn = useAdminCancelReturn(
returnId
)
// ...

const handleCancel = () => {
cancelReturn.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.returns)
}
})
}

// ...
}

export default Return

Hook Parameters

idstringRequired
The return's ID.

Mutation Function Returned Data

AdminReturnsCancelResAdminReturnsCancelResRequired
The associated order's details.

Queries

useAdminReturns

This hook retrieves a list of Returns. The returns can be paginated.

Example

import React from "react"
import { useAdminReturns } from "medusa-react"

const Returns = () => {
const { returns, isLoading } = useAdminReturns()

return (
<div>
{isLoading && <span>Loading...</span>}
{returns && !returns.length && (
<span>No Returns</span>
)}
{returns && returns.length > 0 && (
<ul>
{returns.map((returnData) => (
<li key={returnData.id}>
{returnData.status}
</li>
))}
</ul>
)}
</div>
)
}

export default Returns

Query Returned Data

limitnumberRequired
The maximum number of items that can be returned in the list.
offsetnumberRequired
The number of items skipped before the returned items in the list.
countnumberRequired
The total number of items available.
returnsReturn[]Required
An array of returns details.
Was this section helpful?