# SMS API

import { Badge } from '@astrojs/starlight/components';

<Aside type="caution" title="/createSMSMessage เลิกใช้งานแล้ว">
การผสานรวมใหม่ควรใช้ [Messaging API v2](/th/developer/api-reference/messaging-api-v2/) — ส่ง `platforms: ["SMS"]` ไปยัง `Notify` ดู [คู่มือการย้าย](/th/developer/api-reference/messaging-api-v2/migration-from-v1/#from-createsmsmessage)
</Aside>

<Aside type="note">
ก่อนส่งข้อความ SMS ให้เชื่อมต่อผู้ให้บริการ SMS ของคุณใน Control Panel [เรียนรู้เพิ่มเติม](/th/developer/first-steps/connect-messaging-services/sms-configuration/)
</Aside>

## createSMSMessage <Badge text="เลิกใช้งานแล้ว" variant="caution" size="small" />

ใช้เพื่อส่งการแจ้งเตือนทาง SMS ไปยังผู้ใช้

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

### เนื้อหาของคำขอ (Request body)

| ชื่อ                           | จำเป็น | ประเภท    | คำอธิบาย                                                                                                  |
|--------------------------------|----------|---------|--------------------------------------------------------------------------------------------------------------|
| **auth***                      | ใช่      | string  | [API access token](/th/developer/api-reference/api-identifiers/#api-access-token) จาก Pushwoosh Control Panel                                                               |
| **application***               | ใช่      | string  | [รหัสแอปพลิเคชัน Pushwoosh (Pushwoosh application code)](/th/developer/api-reference/api-identifiers/#application-code)                                                                                 |
| **notifications***             | ใช่      | array   | การตั้งค่าเนื้อหา อาร์เรย์ JSON ของพารามิเตอร์ข้อความ ดูรายละเอียดด้านล่าง                                       |

**พารามิเตอร์การแจ้งเตือน**

| ชื่อ                             | จำเป็น | ประเภท    | คำอธิบาย                                                                                                                                                                                   |
|----------------------------------|----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **send_date***                   | ใช่      | string  | วันที่และเวลาที่จะส่งการแจ้งเตือน ใช้รูปแบบ `YYYY-MM-DD HH:mm` หรือ `now` เพื่อส่งทันที                                                                                           |
| **content***                     | ใช่      | string  | เนื้อหาข้อความของ SMS                                                                                                                                                              |
| **devices***                     | ใช่      | array   | หมายเลขโทรศัพท์ของลูกค้า (ต้องเชื่อมโยงกับ UserId โดยใช้ `/registerDevice` และระบุในพารามิเตอร์ `hwid` หรือใช้ `use_auto_registration`) สามารถระบุได้เพียงหมายเลขเดียวที่นี่ |
| **use_auto_registration**        | ไม่       | boolean | หากตั้งค่าเป็น `true` หมายเลขโทรศัพท์ที่ระบุในพารามิเตอร์ `devices` จะถูกลงทะเบียนโดยอัตโนมัติ                                                                                      |
| **dynamic_content_placeholders** | ไม่       | object  | ตัวยึดตำแหน่งเนื้อหาแบบไดนามิกเพื่อปรับแต่งเนื้อหาข้อความ ตัวยึดตำแหน่งแต่ละตัวจะถูกแทนที่ด้วยค่าไดนามิกที่สอดคล้องกัน                                                           |
| **preset**                       | ไม่       | string  | SMS [Preset Code](/th/developer/api-reference/api-identifiers/#preset-code) จาก Control Panel ของคุณ                                                                                                                                                      |

### ตัวอย่างคำขอ (Request example)

```json
{
  "request": {
    "application": "12345-67891",    // required. Pushwoosh application code.
    "auth": "yxoPUlwqm…………pIyEX4H",  // required. API access token from Pushwoosh Control Panel.
    "notifications": [{
      "send_date": "now",            // required. YYYY-MM-DD HH:mm OR "now".
      "content": "Hello!",           // required. SMS text (string).
      "devices": ["+1234567890"],    // required. Customer phone number (must be associated with
                                     //           a UserId using. /registerDevice and specified in
                                     //           the "hwid" parameter or use "use_auto_registration").
                                     //           Only one number can be specified here.
      "preset": "XXXXX-XXXXX",       // optional. SMS Preset Code from your Control Panel.
      "use_auto_registration": true  // optional. Automatically register phone number specified
                                     //           in "devices" parameter.
    }]
  }
}
```

### ตัวอย่างการตอบกลับ (Response example)

```json
{
  "status_code": 200,
  "status_message": "OK",
  "response": {
    "Messages": [
      "9648-0B10ECB6-0D9F214D"
    ]
  }
}
```

### การตอบกลับข้อผิดพลาด (Error response)
```json
{
  "status_code": 210,
  "status_message": "Invalid devices list. \"devices\" must be an array.",
  "response": {
    "Messages": []
  }
}
```

<Aside type="note">
ในปัจจุบัน SMS แต่ละรายการจะต้องส่งในคำขอแยกต่างหากสำหรับลูกค้าแต่ละราย
</Aside>

หากต้องการดูสถิติ SMS ให้ใช้วิธีการ [totalsByIntervals](/th/developer/api-reference/statistics-api/message-statistics-api/#totalsbyintervals)

คุณยังสามารถดูสถิติสำหรับแต่ละข้อความได้ในส่วน [ประวัติข้อความ (Message History)](/th/product/statistics-and-analytics/message-history/)

<Aside type="caution">
โปรดทราบว่าผู้ให้บริการมือถือบางรายไม่ได้ส่งข้อมูลสถานะการจัดส่ง ดังนั้นสถิติอาจไม่ถูกต้อง คุณสามารถตรวจสอบรายละเอียดกับผู้ให้บริการมือถือที่ให้บริการหมายเลขแก่ลูกค้าของคุณได้
</Aside>