# Create a stock location

URL: https://docs.sparklayer.io/developers/api/stock/create-a-stock-location
Operation: `POST /api/v1/stock-locations` (operationId `createStockLocation`)
OpenAPI spec: https://docs.sparklayer.io/openapi/stock.yaml

`name` and `external_id` are required, and `external_id` must be unique for the site: a duplicate returns `409`. Returns the new location, including its SparkLayer `id`.

`POST /api/v1/stock-locations`

**Base URLs:** `https://app.sparklayer.io` (Live), `https://test.app.sparklayer.io` (Test)

**Authentication:** send `Authorization: Bearer <access_token>` and `Site-Id: <site id>` with every request. Get the token from [Get an access token](https://docs.sparklayer.io/developers/api/core/get-an-access-token.md); see [Authentication](https://docs.sparklayer.io/developers/authentication.md).

### Example request

```bash
curl -X POST "https://app.sparklayer.io/api/v1/stock-locations" \
  -H "Authorization: Bearer $SPARKLAYER_TOKEN" \
  -H "Site-Id: $SPARKLAYER_SITE_ID" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Stock Warehouse 1",
  "external_id": "warehouse-1"
}'
```

Set `SPARKLAYER_TOKEN` to an access token and `SPARKLAYER_SITE_ID` to your Site ID. For the test environment, use `https://test.app.sparklayer.io`.

### Header parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Site-Id` | string | Yes | Your SparkLayer Site ID, from Settings > API in the SparkLayer Dashboard. Example: `jones-climbing` |

### Request body (`application/json`) (required)

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | Name. Length: max 255. |
| `external_id` | string | Yes | External ID (must be unique for the site). Length: max 255. |

```json
{
  "name": "Stock Warehouse 1",
  "external_id": "warehouse-1"
}
```

### Responses

#### 200: The new stock location, including its SparkLayer `id`.

The `StockLocation` object: the request body's fields, plus:

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string (uuid) | | SparkLayer site Stock Location ID |
| `created_at` | string (date-time) | | |
| `updated_at` | string (date-time) | | |

```json
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "name": "Stock Warehouse 1",
  "external_id": "warehouse-1",
  "created_at": "2026-01-31T09:00:00Z",
  "updated_at": "2026-01-31T09:00:00Z"
}
```

#### Other statuses: An error. The body describes the problem: see [Errors](https://docs.sparklayer.io/developers/errors.md).

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `detail` | string | | Human-readable summary of the error |
| `status` | integer | | HTTP Status code returned from API |
| `title` | string | | Machine-readable error code |
| `type` | string \| null | | |
| `errors` | object[] \| null | | A list of errors related to the call |
| `errors[].code` | string | | Machine-readable error code |
| `errors[].property` | string | | The property the error relates to |
| `errors[].message` | string | | Human readable summary of the error |

```json
{
  "detail": "Data Validation Failed",
  "status": 400,
  "title": "invalid-api-request-contents",
  "type": "https://docs.sparklayer.io/api/errors#invalid-api-request-contents",
  "errors": [
    {
      "code": "resource-not-found",
      "property": "stock_location_id",
      "message": "stock_location_id not found"
    }
  ]
}
```
