SwapsResource
This class is used to send requests to Store Swap API Routes. All its method
are available in the JS Client under the medusa.swaps
property.
A swap is created by a customer or an admin to exchange an item with a new one. Creating a swap implicitely includes creating a return for the item being exchanged.
Related Guide: How to create a swap in a storefront
Methods
create
Create a Swap for an Order. This will also create a return and associate it with the swap. If a return shipping option is specified, the return will automatically be fulfilled. To complete the swap, you must use the CartsResource.complete method passing it the ID of the swap's cart.
An idempotency key will be generated if none is provided in the header Idempotency-Key
and added to
the response. If an error occurs during swap creation or the request is interrupted for any reason, the swap creation can be retried by passing the idempotency
key in the Idempotency-Key
header.
Example
Parameters
The data of the swap to be created.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<StoreSwapsRes>RequiredResolves to the swap's details.
ResponsePromise
ResponsePromise<StoreSwapsRes>RequiredretrieveByCartId
Retrieve a Swap's details by the ID of its cart.
Example
Parameters
cart_id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<StoreSwapsRes>RequiredResolves to the swap's details.
ResponsePromise
ResponsePromise<StoreSwapsRes>Required