---
# System prepended metadata

title: VPlatform API Reference

---

# VPlatform API Reference

## REST VRich Server To VPlatform

### Note
```
   ในส่วนนี้จะมีการเพิ่ม API KEY ในภายหลัง
```
---
### Register Shop
`POST` https://server-dev.vlineapp.com/shop

Example Request
```json
{
    "code": "acb",
    "tiktokUsername": "exampleUsername"
    "displayName": "My Shop 001"
}
```
Example Response
```json
{
    "result": {
        "id": "3",
        "code": "zcx",
        "displayName": "My Shop 001",
        "tiktokUsername": "exampleUsername",
        "facebookId": null,
        "status": "ACTIVE",
        "updatedAt": "2021-11-24T08:39:06.602Z",
        "createdAt": "2021-11-24T08:39:06.602Z"
    }
}
```
หลังจาก Register Shop สามาถตรวจสอบ ได้ที่
https://office-dev.vlineapp.com/Shop
---
### Update Shop Stock
`PUT` https://server-dev.vlineapp.com/shop/{code}/stock

Example Request
```json
{
  "stockId": ["f01","f02"]
}
```
Example Response
```json
{
  "success" : true
}
```
---
### Get Shop Stock
`GET` https://server-dev.vlineapp.com/shop/{code}/stock

Example Response
```json
{
  "result" : ["f01","f02"]
}
```
---
### Get Shop Token for chat
`GET` https://server-dev.vlineapp.com/shop/{code}/token

Example Response
```json
{
  "token" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic2hvcCIsImNvZGUiOiJhYmRldiIsInRva2VuVmVyc2lvbiI6IjFkNTdiMzJjMWE3Y2ZjOTBiMjhiMWEwZWY2MTIzNzVlIiwiaWF0IjoxNjM3ODE0NDE3LCJleHAiOjE2NDA0MDY0MTd9.THWROV7tz1WJsx4n6hU7Wy6mk_OpXCLK4Q8W1Hco_4Q"
}
```
---
### Get Shop Profile
`GET` https://server-dev.vlineapp.com/shop/{code}/profile

Example Response
```json
{
    "id": "1",
    "code": "abdev",
    "status": "ACTIVE",
    "tiktokUsername": "pigrabb_b",
    "facebookId": null,
}
```
---
### Collect Order Detail 
***Note โครงเบื้องต้น

`POST` https://server-dev.vlineapp.com/message/{code}/order

Example Request
```json
{
    "customerId": 123,
    "type": "ORDER_DETAIL",    // [ORDER_DETAIL, ORDER_TRACKING, ORDER_CONFIRM]
    "detail" : {
        "message" : "https://shopCode.example.com/order?id=1"
        // สามารถใส่เพิ่มเติมได้
    }
}
```
Example Response
```json
{
    "result": {
        "id": "3",
        "code": "zcx",
        "customerId": 123,
        "facebookId": null,
        "status": "ACTIVE",
        "updatedAt": "2021-11-24T08:39:06.602Z",
        "createdAt": "2021-11-24T08:39:06.602Z"
    }
}
```
---
## REST VPlatform To VRich Server
### Send Live Messages

`Medthod` POST

Example Request
```json=
    {    
        "messages" : [
            {
                "shopCode" : "test",
                "message" : "cf01 = 1",
                "customerId" : 123,
                "tiktokUsername" : "sadfasd",
                "displayName" : "test"
            },
            {
                "shopCode" : "test",
                "message" : "cf01 = 1",
                "customerId" : 123,
                "tiktokUsername" : "sadfasd",
                "displayName" : "test"
            }
        ]

    }
```

---
## Websocket VRich Client to VPlatform(listener)

### Connect WebSocket
`Address` https://server-dev.vlineapp.com
`path` /secure
`token` required

Query Example 
```json=
{
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoidXNlciIsImlkIjoiMSIsInVzZXJuYW1lIjoiY3VzdG9tZXIwNSIsInRva2VuVmVyc2lvbiI6IjVlODc0MTU2NzdiMGMxMDIzZTg5MTU2Yjk1MzRiMGNlIiwiaWF0IjoxNjM3Mzg5MjI3LCJleHAiOjE2Mzk5ODEyMjd9.OILSlaVt6EUmU8TFRDSxYezWgdI8DGHc6zQ9HjV9Nys",
},
```

---

### Event Send Message

#### emit: sendMessage
#### listen: message

Example Request
```json=
{
    "targetId": 1, 
    "type": "TEXT",
    "channel": "VRICH",
    "content": "ab",              // text string
    "senderMsgId": 1626332400000, // for frontend check message was sent
}
```

Example Response
```json=
{
  "shopMsg": false,                // boolean
  "tstamp": "2021-11-12T08:42:45.665Z",
  "type": "TEXT",                  // "TEXT", "IMAGE" 
  "channel": "VRICH",            // "VTIKTOK", "VRICH", "TIKTOK" 
  "content": "ab",                 // string
  "CustomerId": 1,
  "ShopId": 1,
  "senderMsgId": 1626332400000
}
```
---

### Event Send Image

#### emit: sendMessage
#### listen: message

Example Request
```json=
{
    "targetId": 1, 
    "type": "IMAGE",
    "channel": "VRICH",
    "content": '{"originalContentUrl":"https://example.com/original.jpg","previewImageUrl":"https://example.com/preview.jpg"}' // JSON.stringify
    "senderMsgId": 1626332400000, // for frontend check message was sent
}
```

Example Response
```json=
{
  "shopMsg": false,
  "tstamp": "2021-11-12T08:42:45.665Z",
  "type": "IMAGE",
  "channel": "VTIKTOK",
  "content": '{"originalContentUrl":"https://example.com/original.jpg","previewImageUrl":"https://example.com/preview.jpg"}',
  "CustomerId": 1,
  "ShopId": 1,
  "senderMsgId": 1626332400000
}
```

---

### Event Get Messages

#### emit: getMessages
#### listen: getMessages

Example Request
```json=
{
    "targetId": 1,
    "cursor": 1639723533336,        //timestamp | undefined
    "limit": 5                      //number | undefined
}
```

Example Response
```json=
[
  {
    "id": 1,
    "shopMsg": false,
    "tstamp": "2021-11-12T08:42:45.665Z",
    "type": "TEXT",
    "channel": "VTIKTOK",
    "content": "ab",
    "CustomerId": 1,
    "ShopId": 1,
    "senderMsgId": 1626332400000
  }
]
```

---

### Event Get Preview Messages

#### emit: getPreviewMsgs
#### listen: getPreviewMsgs

Example Request
```json=
{
    "cursor": 1639723533336,        //timestamp | undefined
    "limit": 5                      //number | undefined
}
```

Example Response
```json=
[
    {
        "id": "1",
        "ShopId": "1",
        "CustomerId": "1",
        "shopLatestReadId": "138",
        "cusLatestReadId": "139",
        "latestMsgId": "139",
        "updatedAt": "2021-11-30T02:52:16.497Z",
        "type": "TEXT",
        "content": "test Message",
        "shopCode": "acb",
        "shopDisplayName": "acb display name",
        "cusDisplayName": "customer05",
        "cusImageUrl": "https://lh3.googleusercontent.com/a/AATXAJwP21TUhu6615Vl0b2cSUrYg83DL-pQ7EE_SmC0=s96-c",
        "tstamp": "2022-01-10T09:29:53.458Z",
        "cusTiktokUsername": "asd"      // string | null
    }
]
```

---