Skip to main content
Skip to main content

AdminReservationsResource

This class is used to send requests to Admin Reservation API Routes. To use these API Routes, make sure to install the @medusajs/inventory module in your Medusa backend.

All methods in this class require authentication. The methods are available in the JS Client under the medusa.admin.reservations property.

Reservations, provided by the Inventory Module, are quantities of an item that are reserved, typically when an order is placed but not yet fulfilled. Reservations can be associated with any resources, but commonly with line items of an order.

Related Guide: How to manage item allocations in orders.

Methods

retrieve

Retrieve a reservation'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.reservations.retrieve(reservationId)
.then(({ reservation }) => {
console.log(reservation.id);
})

Parameters

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

Default: {}

Returns

ResponsePromiseResponsePromise<AdminReservationsRes>Required
Resolves to the reservation's details.

list

Retrieve a list of reservations. The reservations can be filtered by fields such as location_id or quantity passed in the query parameter. The reservations can also be paginated.

Example

To list reservations:

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.reservations.list()
.then(({ reservations, count, limit, offset }) => {
console.log(reservations.length)
})

To specify relations that should be retrieved within the reservations:

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.reservations.list({
expand: "location"
})
.then(({ reservations, count, limit, offset }) => {
console.log(reservations.length)
})

By default, only the first 20 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.reservations.list({
expand: "location",
limit,
offset
})
.then(({ reservations, count, limit, offset }) => {
console.log(reservations.length)
})

Parameters

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

Default: {}

Filters and pagination parameters to apply on the retrieved reservations.

Returns

ResponsePromiseResponsePromise<AdminReservationsListRes>Required
Resolves to the list of reservations with pagination fields.

create

Create a reservation which can be associated with any resource, such as an order's line item.

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.reservations.create({
line_item_id: "item_123",
location_id: "loc_123",
inventory_item_id: "iitem_123",
quantity: 1
})
.then(({ reservation }) => {
console.log(reservation.id);
});

Parameters

The reservation to be created.
customHeadersRecord<string, unknown>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminReservationsRes>Required
Resolves to the reservation's details.

update

Update a reservation'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.reservations.update(reservationId, {
quantity: 3
})
.then(({ reservation }) => {
console.log(reservation.id);
});

Parameters

idstringRequired
The ID of the reservation.
The attributes to update in the reservation.
customHeadersRecord<string, unknown>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminReservationsRes>Required
Resolves to the reservation's details.

delete

Delete a reservation. Associated resources, such as the line item, will not be deleted.

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.reservations.delete(reservationId)
.then(({ id, object, deleted }) => {
console.log(id);
});

Parameters

idstringRequired
The ID of the reservation.
customHeadersRecord<string, unknown>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<DeleteResponse>Required
Resolves to the deletion operation's details.
Was this section helpful?