---
displayed_sidebar: jsClientSidebar
slug: /references/js-client/AdminStockLocationsResource
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# AdminStockLocationsResource

This class is used to send requests to [Admin Stock Location API Routes](https://docs.medusajs.com/api/admin#stock-locations). To use these API Routes, make sure to install the
[@medusajs/stock-location](https://docs.medusajs.com/modules/multiwarehouse/install-modules#stock-location-module) module in your Medusa backend.

All methods in this class require [user authentication](js_client.AdminAuthResource.mdx#createsession). The methods
are available in the JS Client under the `medusa.admin.stockLocations` property.

A stock location, provided by the [Stock Location module](https://docs.medusajs.com/modules/multiwarehouse/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](https://docs.medusajs.com/modules/multiwarehouse/admin/manage-stock-locations).

## Methods

### create

Create a stock location.

#### Example

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

<ParameterTypes parameters={[
  {
    "name": "payload",
    "type": "[AdminPostStockLocationsReq](../../medusa/classes/medusa.AdminPostStockLocationsReq.mdx)",
    "description": "The stock location to be created.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "address",
        "type": "[StockLocationAddress](../../medusa/classes/medusa.StockLocationAddress.mdx)",
        "description": "A new stock location address to create and associate with the stock location. Only required if `address\\_id` is not provided.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "address_1",
            "type": "`string`",
            "description": "Stock location address",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "address_2",
            "type": "`string`",
            "description": "Stock location address' complement",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "city",
            "type": "`string`",
            "description": "Stock location address' city",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "company",
            "type": "`string`",
            "description": "Stock location address' company",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "country_code",
            "type": "`string`",
            "description": "The two character ISO code for the country.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "phone",
            "type": "`string`",
            "description": "Stock location address' phone number",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "postal_code",
            "type": "`string`",
            "description": "Stock location address' postal code",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "province",
            "type": "`string`",
            "description": "Stock location address' province",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      },
      {
        "name": "address_id",
        "type": "`string`",
        "description": "the ID of an existing stock location address to associate with the stock location. Only required if `address` is not provided.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "metadata",
        "type": "`Record<string, unknown>`",
        "description": "An optional key-value map with additional details",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "name",
        "type": "`string`",
        "description": "the name of the stock location",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  },
  {
    "name": "customHeaders",
    "type": "`Record<string, any>`",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} expandUrl="https://docs.medusajs.com/js-client/overview#expanding-fields"/>

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "ResponsePromise&#60;AdminStockLocationsRes&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the stock location's details.",
    "expandable": false,
    "children": [
      {
        "name": "stock_location",
        "type": "[StockLocationExpandedDTO](../../medusa/types/medusa.StockLocationExpandedDTO.mdx)",
        "description": "Stock location details.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "sales_channels",
            "type": "`any`[]",
            "description": "The associated sales channels.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      }
    ]
  }
]} />

___

### delete

Delete a stock location.

#### Example

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

<ParameterTypes parameters={[
  {
    "name": "id",
    "type": "`string`",
    "description": "The stock location's ID.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customHeaders",
    "type": "`Record<string, any>`",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} expandUrl="https://docs.medusajs.com/js-client/overview#expanding-fields"/>

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "ResponsePromise&#60;[DeleteResponse](../../medusa/types/medusa.DeleteResponse-1.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the deletion operation's details.",
    "expandable": false,
    "children": [
      {
        "name": "deleted",
        "type": "`boolean`",
        "description": "Whether the item was deleted successfully.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "id",
        "type": "`string`",
        "description": "The ID of the item that was deleted.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "object",
        "type": "`string`",
        "description": "The type of the item that was deleted.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  }
]} />

___

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

```ts
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:

```ts
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:

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

<ParameterTypes parameters={[
  {
    "name": "query",
    "type": "[AdminGetStockLocationsParams](../../medusa/classes/medusa.AdminGetStockLocationsParams.mdx)",
    "description": "Filters and pagination configurations to apply on the retrieved stock locations.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "address_id",
        "type": "`string` \\| `string`[]",
        "description": "Filter stock locations by the ID of their associated addresses.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "expand",
        "type": "`string`",
        "description": "Comma-separated relations that should be expanded in the returned data.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "fields",
        "type": "`string`",
        "description": "Comma-separated fields that should be included in the returned data.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "id",
        "type": "`string` \\| `string`[]",
        "description": "IDs to filter stock locations by.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "limit",
        "type": "`number`",
        "description": "Limit the number of items returned in the list.",
        "optional": true,
        "defaultValue": "20",
        "expandable": false,
        "children": []
      },
      {
        "name": "name",
        "type": "`string` \\| `string`[]",
        "description": "Names to filter stock locations by.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "offset",
        "type": "`number`",
        "description": "The number of items to skip when retrieving a list.",
        "optional": true,
        "defaultValue": "0",
        "expandable": false,
        "children": []
      },
      {
        "name": "sales_channel_id",
        "type": "`string` \\| `string`[]",
        "description": "Filter stock locations by the ID of their associated sales channels.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  },
  {
    "name": "customHeaders",
    "type": "`Record<string, any>`",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} expandUrl="https://docs.medusajs.com/js-client/overview#expanding-fields"/>

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "ResponsePromise&#60;AdminStockLocationsListRes&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the list of stock locations with pagination fields.",
    "expandable": false,
    "children": [
      {
        "name": "AdminStockLocationsListRes",
        "type": "[PaginatedResponse](../../medusa/types/medusa.PaginatedResponse-1.mdx) & `object`",
        "description": "The list of stock locations with pagination fields.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "count",
            "type": "`number`",
            "description": "",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "limit",
            "type": "`number`",
            "description": "",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "offset",
            "type": "`number`",
            "description": "",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "stock_locations",
            "type": "[StockLocationExpandedDTO](../../medusa/types/medusa.StockLocationExpandedDTO.mdx)[]",
            "description": "",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      }
    ]
  }
]} />

___

### retrieve

Retrieve a stock location's details.

#### Example

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

<ParameterTypes parameters={[
  {
    "name": "itemId",
    "type": "`string`",
    "description": "The stock location's ID.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customHeaders",
    "type": "`Record<string, any>`",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} expandUrl="https://docs.medusajs.com/js-client/overview#expanding-fields"/>

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "ResponsePromise&#60;AdminStockLocationsRes&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the stock location's details.",
    "expandable": false,
    "children": [
      {
        "name": "stock_location",
        "type": "[StockLocationExpandedDTO](../../medusa/types/medusa.StockLocationExpandedDTO.mdx)",
        "description": "Stock location details.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "sales_channels",
            "type": "`any`[]",
            "description": "The associated sales channels.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      }
    ]
  }
]} />

___

### update

Update a stock location's details.

#### Example

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

<ParameterTypes parameters={[
  {
    "name": "stockLocationId",
    "type": "`string`",
    "description": "The stock location's ID.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "payload",
    "type": "[AdminPostStockLocationsLocationReq](../../medusa/classes/medusa.AdminPostStockLocationsLocationReq.mdx)",
    "description": "The attributes to be updated in the stock location.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "address",
        "type": "[StockLocationAddress](../../medusa/classes/medusa.StockLocationAddress-1.mdx)",
        "description": "The data of an associated address to create or update.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "address_1",
            "type": "`string`",
            "description": "First line address.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "address_2",
            "type": "`string`",
            "description": "Second line address.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "city",
            "type": "`string`",
            "description": "City.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "company",
            "type": "`string`",
            "description": "Company.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "country_code",
            "type": "`string`",
            "description": "Country code.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "phone",
            "type": "`string`",
            "description": "Phone.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "postal_code",
            "type": "`string`",
            "description": "Postal code.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "province",
            "type": "`string`",
            "description": "Province.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      },
      {
        "name": "address_id",
        "type": "`string`",
        "description": "the stock location address ID",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "metadata",
        "type": "`Record<string, unknown>`",
        "description": "An optional key-value map with additional details",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "name",
        "type": "`string`",
        "description": "the name of the stock location",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  },
  {
    "name": "customHeaders",
    "type": "`Record<string, any>`",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} expandUrl="https://docs.medusajs.com/js-client/overview#expanding-fields"/>

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "ResponsePromise&#60;AdminStockLocationsRes&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the stock location's details.",
    "expandable": false,
    "children": [
      {
        "name": "stock_location",
        "type": "[StockLocationExpandedDTO](../../medusa/types/medusa.StockLocationExpandedDTO.mdx)",
        "description": "Stock location details.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "sales_channels",
            "type": "`any`[]",
            "description": "The associated sales channels.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      }
    ]
  }
]} />
