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 user 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
Parameters
id
stringRequiredcustomHeaders
Record<string, unknown>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminReservationsRes>RequiredResolves to the reservation's details.
ResponsePromise
ResponsePromise<AdminReservationsRes>Requiredlist
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:
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
customHeaders
Record<string, unknown>RequiredDefault: {}
Filters and pagination parameters to apply on the retrieved reservations.
Returns
ResponsePromise
ResponsePromise<AdminReservationsListRes>RequiredResolves to the list of reservations with pagination fields.
ResponsePromise
ResponsePromise<AdminReservationsListRes>Requiredcreate
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.
customHeaders
Record<string, unknown>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminReservationsRes>RequiredResolves to the reservation's details.
ResponsePromise
ResponsePromise<AdminReservationsRes>Requiredupdate
Update a reservation's details.
Example
Parameters
id
stringRequiredThe attributes to update in the reservation.
customHeaders
Record<string, unknown>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminReservationsRes>RequiredResolves to the reservation's details.
ResponsePromise
ResponsePromise<AdminReservationsRes>Requireddelete
Delete a reservation. Associated resources, such as the line item, will not be deleted.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, unknown>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<DeleteResponse>RequiredResolves to the deletion operation's details.
ResponsePromise
ResponsePromise<DeleteResponse>Required