Skip to main content
Skip to main content

AdminSwapsResource

This class is used to send requests to Admin Swap API Routes. All its method are available in the JS Client under the medusa.admin.swaps property.

All methods in this class require authentication.

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 manage swaps

Methods

retrieve

Retrieve a swap's details.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.swaps.retrieve(swapId)
.then(({ swap }) => {
console.log(swap.id);
})

Parameters

idstringRequired
The swap's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminSwapsRes>Required
Resolves to the swap's details.

list

Retrieve a list of swaps. The swaps can be paginated.

Example

To list swaps:

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.swaps.list()
.then(({ swaps }) => {
console.log(swaps.length);
})

By default, only the first 50 records are retrieved. You can control pagination by specifying the limit and offset properties:

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.swaps.list({
limit,
offset
})
.then(({ swaps }) => {
console.log(swaps.length);
})

Parameters

customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Pagination configurations to apply on the retrieved swaps.

Returns

ResponsePromiseResponsePromise<AdminSwapsListRes>Required
Resolves to the list of swaps with pagination fields.
Was this section helpful?