AdminStockLocationsResource
This class is used to send requests to Admin Stock Location API Routes. To use these API Routes, make sure to install the @medusajs/stock-location 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.stockLocations
property.
A stock location, provided by the Stock Location module, indicates a physical address that stock-kept items, such as physical products, can be stored in. An admin can create and manage available stock locations.
Related Guide: How to manage stock locations.
Methods
create
Create a stock location.
Example
Parameters
The stock location to be created.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminStockLocationsRes>RequiredResolves to the stock location's details.
ResponsePromise
ResponsePromise<AdminStockLocationsRes>Requireddelete
Delete a stock location.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
Resolves to the deletion operation's details.
list
Retrieve a list of stock locations. The stock locations can be filtered by fields such as name
or created_at
passed in the query
parameter.
The stock locations can also be sorted or paginated.
Example
To list stock locations:
To specify relations that should be retrieved within the stock locations:
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.stockLocations.list({
expand: "address"
})
.then(({ stock_locations, limit, offset, count }) => {
console.log(stock_locations.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.stockLocations.list({
expand: "address",
limit,
offset
})
.then(({ stock_locations, limit, offset, count }) => {
console.log(stock_locations.length);
})
Parameters
Filters and pagination configurations to apply on the retrieved stock locations.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminStockLocationsListRes>RequiredResolves to the list of stock locations with pagination fields.
ResponsePromise
ResponsePromise<AdminStockLocationsListRes>Requiredretrieve
Retrieve a stock location's details.
Example
Parameters
itemId
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminStockLocationsRes>RequiredResolves to the stock location's details.
ResponsePromise
ResponsePromise<AdminStockLocationsRes>Requiredupdate
Update a stock location'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.stockLocations.update(stockLocationId, {
name: 'Main Warehouse'
})
.then(({ stock_location }) => {
console.log(stock_location.id);
})
Parameters
stockLocationId
stringRequiredThe attributes to be updated in the stock location.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminStockLocationsRes>RequiredResolves to the stock location's details.
ResponsePromise
ResponsePromise<AdminStockLocationsRes>Required