# Warehouse

> Base URL: `https://pos.pages.fm/api/v1`. Authenticate with the `api_key` query parameter.

## Warehouse list

`GET /shops/{SHOP_ID}/warehouses`

Get list of warehouses

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Shop ID |

### Responses

- `200` Success (object)

```json
{
  "data": [
    {
      "id": "b4cb5897-6e56-4581-96cc-2f12677c7bd8",
      "name": "kho test ecod",
      "address": "hâhhha",
      "full_address": "hâhhha, Xã Bình Trung, Huyện Châu Đức, Bà Rịa-Vũng Tàu",
      "phone_number": "0999999999",
      "province_id": "717",
      "district_id": "71705",
      "commune_id": "7170510",
      "country_code": "84",
      "shop_id": 26290,
      "allow_create_order": true,
      "custom_id": null,
      "affiliate_shop_id": 26290,
      "affiliate_warehouse": "Kho gia dụng"
    },
    {
      "id": "644b0063-e9a8-43cd-ba08-66a8066d462e",
      "name": "kho 2",
      "address": "19/349 Minh Khai , Hai bà Trưng, Hà Nội",
      "full_address": "19/349 Minh Khai , Hai bà Trưng, Hà Nội, Phường Minh Khai, Quận Hai Bà Trưng, Hà Nội",
      "phone_number": "01655809949",
      "province_id": "101",
      "district_id": "10107",
      "commune_id": "1010735",
      "country_code": "84",
      "shop_id": 26290,
      "allow_create_order": false,
      "custom_id": null
    },
    {
      "id": "3cfcf3ab-dd77-4237-862f-356b3506fe8a",
      "name": "kho địa chỉ mới",
      "address": "34234234",
      "full_address": "34234234, Xã Cao Đức, Bắc Ninh",
      "phone_number": "0989965976",
      "province_id": "84_VN102",
      "district_id": null,
      "commune_id": "84_VN10236",
      "country_code": "84",
      "shop_id": 26290,
      "allow_create_order": true,
      "custom_id": null
    }
  ]
}
```

## Create warehouse

`POST /shops/{SHOP_ID}/warehouses`

Create warehouses

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Shop ID |

### Request body

Request body containing warehouse information to create

- `name` (string, required): Warehouse name
- `address` (string): Warehouse address
- `phone_number` (string): Warehouse phone number
- `province_id` (string): Province ID. Get by API GET /geo/provinces
- `district_id` (string): District ID. Get by API GET /geo/districts
- `commune_id` (string): Commune ID. Get by API GET /geo/communes
- `country_code` (string): Country code
- `shelf_config` (object, required): Shelf config
  - `col` (string): Column
- `batch_config` (object): Batch config
  - `col` (string): Column
  - `line` (string): Line
  - `row` (string): Row
- `custom_shelf_config` (object): Custom shelf config
  - `custom_config` (object): Custom config
- `custom_batch_config` (object): Custom batch config
  - `custom_config` (object): Custom config
- `hide_config_batch_shelf` (boolean): Open custom batch shelf config

```json
{
  "name": "kho 2",
  "address": "19/349 Minh Khai , Hai bà Trưng, Hà Nội",
  "phone_number": "098765432",
  "province_id": "101",
  "district_id": "10107",
  "commune_id": "1010735",
  "country_code": "84",
  "shelf_config": {
    "col": "3"
  },
  "batch_config": {
    "col": "0",
    "line": "3",
    "row": "3"
  },
  "custom_batch_config": {
    "custom_config": {
      "0": "lô 1"
    }
  },
  "custom_shelf_config": {
    "custom_config": {
      "0": "1.1",
      "1": "1.2",
      "2": "1.3",
      "3": "1.4"
    }
  },
  "hide_config_batch_shelf": false
}
```

### Responses

- `200` Success (Warehouse)

```json
{
  "id": "b4cb5897-6e56-4581-96cc-2f12677c7bd8",
  "name": "kho test ecod",
  "address": "hâhhha",
  "full_address": "hâhhha, Xã Bình Trung, Huyện Châu Đức, Bà Rịa-Vũng Tàu",
  "phone_number": "0999999999",
  "province_id": "717",
  "district_id": "71705",
  "commune_id": "7170510",
  "country_code": "84",
  "shop_id": 26290,
  "allow_create_order": true,
  "custom_id": null
}
```

## Update warehouse

`PUT /shops/{SHOP_ID}/warehouses/{WAREHOUSE_ID}`

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Shop ID |
| `WAREHOUSE_ID` | path | string | yes | Warehouse ID |

### Request body

Request body containing warehouse information to update

- `name` (string, required): Warehouse name
- `address` (string): Warehouse address
- `phone_number` (string): Warehouse phone number
- `province_id` (string): Province ID. Get by API GET /geo/provinces
- `district_id` (string): District ID. Get by API GET /geo/districts
- `commune_id` (string): Commune ID. Get by API GET /geo/communes
- `country_code` (string): Country code
- `shelf_config` (object, required): Shelf config
  - `col` (string): Column
- `batch_config` (object): Batch config
  - `col` (string): Column
  - `line` (string): Line
  - `row` (string): Row
- `custom_shelf_config` (object): Custom shelf config
  - `custom_config` (object): Custom config
- `custom_batch_config` (object): Custom batch config
  - `custom_config` (object): Custom config
- `hide_config_batch_shelf` (boolean): Open custom batch shelf config

```json
{
  "name": "Kho mặc định",
  "address": "190 La Thành",
  "phone_number": "0366452565",
  "province_id": "101",
  "district_id": "10113",
  "commune_id": "1011309",
  "country_code": "84",
  "shelf_config": {
    "col": "3"
  },
  "batch_config": {
    "col": "0",
    "line": "3",
    "row": "3"
  },
  "custom_batch_config": {
    "custom_config": {
      "0": "lô 1"
    }
  },
  "custom_shelf_config": {
    "custom_config": {
      "0": "1.1",
      "1": "1.2",
      "2": "1.3",
      "3": "1.4"
    }
  },
  "hide_config_batch_shelf": false
}
```

### Responses

- `200` Success (Warehouse)

```json
{
  "id": "b4cb5897-6e56-4581-96cc-2f12677c7bd8",
  "name": "kho test ecod",
  "address": "SCB",
  "full_address": "SCB, Xã Bình Trung, Huyện Châu Đức, Bà Rịa-Vũng Tàu",
  "phone_number": "0999999999",
  "province_id": "717",
  "district_id": "71705",
  "commune_id": "7170510",
  "country_code": "84",
  "shop_id": 26290,
  "allow_create_order": true,
  "custom_id": null
}
```

## Inventory histories

`GET /shops/{SHOP_ID}/inventory_histories`

Get inventory history

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Shop ID |
| `page` | query | integer | yes | Page number |
| `page_size` | query | integer | yes | Page size |
| `warehouse_id` | query | string |  | Warehouse ID |
| `variation_ids[]` | query | string[] |  | Variation IDs |
| `startDate` | query | integer |  | Start date (unix timestamp) |
| `endDate` | query | integer |  | End date (unix timestamp) |

### Responses

- `200` Success (object)

```json
{
  "success": true,
  "data": [
    {
      "avg_price": 1,
      "current_inventory": [
        {
          "actual_remain_quantity": 1,
          "avg_price": 1,
          "id": "b4cb5897-6e56-4581-96cc-2f12677c7bd8",
          "name": "kho test ecod",
          "remain_quantity": 1,
          "total_quantity": 1
        }
      ],
      "editor_id": "cee3c05e-5f85-43c4-b27e-889b99c50097",
      "id": 1,
      "inserted_at": "2024-01-01T00:00:00Z",
      "quantity": 1,
      "ref_display_id": "12345",
      "remain_quantity": 1,
      "table_name": "Purchase",
      "type": "import",
      "variation_now": {
        "barcode": "BARCODE123",
        "display_id": "13109",
        "fields": [
          {
            "id": "field-id-1",
            "keyValue": "Màu",
            "name": "Màu",
            "value": "Trắng"
          }
        ],
        "id": "415040f4-ab63-465e-8699-e9ebfff4c6c7",
        "images": [
          "https://statics.pancake.vn/user-content.pancake.vn/2021/8/5/fccd6.jpg"
        ],
        "is_hidden": true,
        "is_locked": true,
        "is_sell_negative_variation": true,
        "last_imported_price": 1,
        "product_id": "3487e126-b0d9-4dae-89a9-ee60bef2f4e9",
        "retail_price": 1,
        "weight": 1
      },
      "warehouse": {
        "custom_id": null,
        "ffm_id": null,
        "full_address": "hâhhha, Xã Bình Trung, Huyện Châu Đức, Bà Rịa-Vũng Tàu",
        "id": "b4cb5897-6e56-4581-96cc-2f12677c7bd8",
        "name": "kho test ecod",
        "phone_number": "0999999999"
      }
    }
  ]
}
```
