Skip to main content
Skip to main content

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

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.create({
name: "Main Warehouse",
})
.then(({ stock_location }) => {
console.log(stock_location.id);
})

Parameters

The stock location to be created.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminStockLocationsRes>Required
Resolves to the stock location's details.

retrieve

Retrieve 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.retrieve(stockLocationId)
.then(({ stock_location }) => {
console.log(stock_location.id);
})

Parameters

itemIdstringRequired
The stock location's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminStockLocationsRes>Required
Resolves to the stock location's details.

update

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

stockLocationIdstringRequired
The stock location's ID.
The attributes to be updated in the stock location.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminStockLocationsRes>Required
Resolves to the stock location's details.

delete

Delete a stock location.

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

Parameters

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

Default: {}

Returns

ResponsePromiseResponsePromise<DeleteResponse>Required
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:

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

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

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

Default: {}

Filters and pagination configurations to apply on the retrieved stock locations.

Returns

ResponsePromiseResponsePromise<AdminStockLocationsListRes>Required
Resolves to the list of stock locations with pagination fields.
Was this section helpful?