# Advantech : How to read storeVue UCam data
###### tags: `API Document`
## Concept
#### StoreVue 儲存計數資料的單元主要是依據 monitor
#### 因此搜尋資料時,需要修改為使用 monitor 單元表示
#### 主要是使用 **固定前贅(mo_d_)** 加上 **sensor_id**
#### 例如 mo_d_76:2a:aa:0e:9f:d9
- mo_d_ : 固定前贅
- sensor_id : 76:2a:aa:0e:9f:d9
## Step 1 : 取得 sensor_id
<h3 style="color:Red;"> 此為非必要整合項目,可以透過 API 先取得後直接寫在程式碼(腳本)中</h3>
#### API Url : `https://portals.storevue.com/api/store/info`
#### Method : `POST`
#### Request Parameters
| Property Name | Value Type | Description |
| ------------- | ---------- | --------------- |
| show_delete | boolean | 是否顯示刪除之設備 |
| store_id | String | 希望取得之門店資訊(包含sensor_id) |
| access_key | String | 驗證使用之存取令牌 |
#### Response Parameters
| Property Name | Value Type | Description |
| --------------------------- | ---------- | ----------------------------- |
| status | number | API請求是否成功 |
| store | Object | 門店資訊 |
| store.store_id | String | 門店ID |
| store.store_name | String | 門店名稱 |
| store.acc_id | String | 品牌代碼 |
| store.sensors | Object[]| Sensor列表 |
| store.sensors.sensor_id | String | <h4 style="color:Red;"> Sensor Id,此為最主要使用欄位</h4>|
| store.sensors.sensor_name | String | Sensor 名稱 |
| store.sensors.device_id | String | 設備代碼,可忽略 |
| store.sensors.device_type | String | 設備類型,People Counting則為 UCam,另外還有可能是 V-Pos|
| store.last_update_time | String | 最後更新時間 |
#### Request Payload Sample:
``` json
{
"show_delete" : false,
"store_id" : "m6Rt0gd8sEYN",
"access_key": "asdf123asdf123"
}
```
#### Response payload Sample (此Sample已刪除不必要資訊)
``` json
{
"status": 1
"store": {
"store_id": "m6Rt0gd8sEYN",
"store_name": "香腸博物館",
"acc_id": "cjEfKcwsBP3F",
"sensors": [
{
"sensor_id": "76:2a:aa:0e:9f:d9",
"sensor_name": "BB_Tainan_S01",
"device_id": "MHr@d8Ytk8NS",
"device_type": "UCam",
},
{
"sensor_id": "UHGdKasxzMAp",
"sensor_name": "POS",
"device_id": "Q1kkzngDGDg5",
"device_type": "V-Pos",
}
],
"last_update_time": "2022-10-11 15:19:22"
}
}
```
## Step 2 : 透過Monitor Id取得資料
<h3 style="color:Red;"> 此項目之 Response 與 UShop 有些微差異,須注意</h3>
#### API Url : `https://portals.storevue.com/api/data/retrieve`
#### Method : `POST`
#### Request Parameters
| Property Name | Value Type | Description |
| --------------- | ---------- | --------------- |
| date_range | String[] | 設定之時間範圍 |
| data_unit | String | 取得資料之時間單位 |
| preprocess_type | String | 固定使用 people_counting |
| monitor_ids | String[] | 填入 mo_d_{{sensor_id}} |
| access_key | String | 驗證使用之存取令牌 |
#### Response Parameters
| Property Name | Value Type | Description |
| --------------------------- | ---------- | ----------------------------- |
| status | number | API請求是否成功 |
| retrieved | Object | 取得之資料主要描述單元 |
| retrieved.monitors | Object[] | 門店ID |
| retrieved.monitors.id | String | Monitor ID |
| retrieved.monitors.name | String | Monitor名稱 |
| retrieved.monitors.type | String | Monitor類型,ppc_store_entry為進店人流|
| retrieved.monitors.datas | Object[] | 資料主體 |
| retrieved.monitors.datas.starttime | number | 時間戳,單位到秒(共10碼) |
| retrieved.monitors.datas.content | Object | 資料數據 |
| retrieved.monitors.datas.content.pin | number | 進入人數 |
| retrieved.monitors.datas.content.pout| number | 離開人數 |
#### Request Payload Sample:
``` json
{
"date_range": [
"2022/12/28","2022/12/29"
],
"data_unit":"hh",
"preprocess_type":"people_counting",
"monitor_ids": [
"mo_d_76:2a:aa:0e:9f:d9"
],
"access_key": "asdf123asdf123asdf"
}
```
#### Response payload Sample (此Sample已刪除不必要資訊)
``` json
{
"status": 1,
"retrieved": {
"monitors": [
{
"id": "mo_d_76:2a:aa:0e:9f:d9",
"name": "default",
"type": "ppc_store_entry",
"datas": [
{
"starttime": 1672221599,
"content": {
"pin": 24,
"pout": 24
}
},
{
"starttime": 1672225199,
"content": {
"pin": 29,
"pout": 27
}
},
// 以下省略
]
}
]
}
}
```