# Message inbox API

## getInboxMessages

ส่งคืนรายการข้อความ Inbox สำหรับ HWID ที่ระบุ

`POST` `https://api.pushwoosh.com/json/1.3/getInboxMessages`

#### Request headers

| ชื่อ | จำเป็น | ค่า | คำอธิบาย |
|---|---|---|---|
| Authorization | ใช่ | Token `XXXX` | [API Device Token](/th/developer/api-reference/api-access-token/#device-api-token) เพื่อเข้าถึง Device API แทนที่ `XXXX` ด้วย Device API token จริงของคุณ |

#### Request Body

| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
| application\* | string | [Pushwoosh application code](/th/developer/api-reference/api-identifiers/#application-code) |
| userId\* | string | หากไม่ได้ตั้งค่า [User ID](/th/developer/api-reference/api-identifiers/#user-id) แบบกำหนดเอง ให้ใช้ HWID |
| hwid | string | [Hardware ID ของอุปกรณ์](/th/developer/api-reference/api-identifiers/#hardware-id) ที่จะดึงข้อความ Inbox |
| last\_code | string | รหัสของข้อความล่าสุดที่ดึงมาในการตอบกลับครั้งก่อน หากว่างเปล่า จะส่งคืนข้อความแรกสุด |
| count | integer | จำนวนข้อความที่จะแสดงในการตอบกลับเดียว ใช้สำหรับการแบ่งหน้า (pagination) ใส่ 0 เพื่อโหลดข้อความทั้งหมดใน Inbox |

<Tabs>
<TabItem label="200">
```
{
  "response": {
    "messages": [{                      // array of messages currently stored in user's Inbox
      "inbox_id": "avde1c792cd",
      "rt": "146078676",                // date to remove the message from Inbox
      "send_date": "1459758676",        // date when the message was saved to Inbox
      "order": "59138176",              // position in Inbox presentation order
      "title": "New Rich Media in inbox!",
      "text": "Hi! New feature is available right now!",
      "action_type": "RichMedia",
      "action_params": {                // payload describing the actions on push opening
        "rm": "{\"url\":\"https:\/\/richmedia.pushwoosh.com\/C82F7-51FC1.zip\",\"ts\":\"1459758676\",\"tags\":{\"tagName\":\"tagValue\"}}"
      },
      "status": 1,                      // 1 - delivered, 2 - read, 3 - opened,
                                        // 4 - deleted(by a user), 5 - deleted from Control Panel
      "hash":"1C"                       // hash code of push notification
    }, {
      ...
    }],
    "next":"afarew511",                 // the next Inbox code to be returned by
                                        // the following /getInboxMessages request
    "deleted": ["bbaf85ab", "a41957b"], // the list of messages deleted from Control Panel
    "new_inbox": 6                      // the number of delivered Inbox messages for that user (can be used for badge)
  }
}
```
</TabItem>
</Tabs>

```json title="Example Request"
{
  "request": {
    "application": "XXXXX-XXXXX", // required. Pushwoosh app code
     "userId": "user_name_1",     // required. User ID registered in Pushwoosh
     "device_type": 1             // optional. For device types refer to /registerDevice
  }
}
```

<Aside type="note">
สำหรับ iOS โปรดตรวจสอบให้แน่ใจว่าคุณได้เพิ่ม Notification Service Extension ในโปรเจกต์ของคุณเพื่อติดตามการส่ง push [เรียนรู้เพิ่มเติม](/th/developer/pushwoosh-sdk/ios-sdk/ios-message-delivery-tracking/)
</Aside>

## inboxStatus

อัปเดตสถานะของข้อความ Inbox ที่ระบุ

`POST` `https://api.pushwoosh.com/json/1.3/inboxStatus`

#### Request headers

| ชื่อ | จำเป็น | ค่า | คำอธิบาย |
|---|---|---|---|
| Authorization | ใช่ | Token `XXXX` | [API Device Token](/th/developer/api-reference/api-access-token/#device-api-token) เพื่อเข้าถึง Device API แทนที่ `XXXX` ด้วย Device API token จริงของคุณ |

#### Request Body

| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
| application\* | string | [Pushwoosh application code](/th/developer/api-reference/api-identifiers/#application-code) |
| inbox\_code\* | string | สามารถรับได้จากรายละเอียดข้อความใน Control Panel หรือจากพารามิเตอร์ "order" ของคำขอ `/getInboxMessages` |
| hash | string | รหัส Hash ของข้อความ Inbox |
| hwid | string | [Hardware ID ของอุปกรณ์](/th/developer/api-reference/api-identifiers/#hardware-id) ที่จะอัปเดตสถานะ Inbox |
| time | string | Timestamp ของวันที่ส่ง |
| userID\* | string | หากไม่ได้ตั้งค่า [User ID](/th/developer/api-reference/api-identifiers/#user-id) แบบกำหนดเอง ให้ใช้ HWID |
| status\* | integer | 1 - ส่งแล้ว (delivered), 2 - อ่านแล้ว (read), 3 - เปิดแล้ว (opened), 4 - ลบโดยผู้ใช้ (deleted by a user) |
| device\_type | integer | [ดูค่าที่เป็นไปได้](/th/developer/api-reference/api-identifiers/#device-type) |

<Tabs>
<TabItem label="200">
```json
{
  "status_code": 200,
  "status_message": "OK",
  "response": null
}
```
</TabItem>
</Tabs>

```json title="Example"
{
  "request": {
    "application": "XXXXX-XXXXX",    // required. Pushwoosh application code
    "inbox_code": "874393934032909", // required. "order" parameter of /getInboxMessages request
    "hash": "1C",                    // optional.
    "userId": "some_user",           // required.
    "status": 2,                     // required. status to set: 1-delivered, 2-read, 3-opened, 4-deleted (by a user)
    "device_type": 3                 // optional.
  }
}
```