การย้าย API ระบบเก่า มา ระบบใหม่

ผู้ใช้งานที่ใช้งาน API จากระบบเก่าอยู่แล้ว สามารถเปลี่ยนมาใช้งาน API ของระบบ ใหม่ได้ตาม รายละเอียดด้านล่างดังนี้

URL Endpoint

ระบบเดิม

ระบบใหม่

http://api.ants.co.th

https://api2.ants.co.th

http://api-service.ants.co.th

https://api-service.ants.co.th

Authentication

API ทั้ง 2 ระบบ ใช้รูปแบบการยืนยันตนแบบเดียวกัน คือ “Basic Authentication” โดยการใช้ Username:Password แล้ว Encode ด้วย รูปแบบ Base64

ตัวอย่าง

username = antsuses password = ants1234

format = antsuser:ants1234 encodebase64 = YW50c3VzZXI6YW50czEyMzQ=

POST /sms/send HTTP/1.1
Host: api-service.ants.co.th
Content-Type: application/json
Authorization: Basic YW50c3VzZXI6YW50czEyMzQ=
Cache-Control: no-cache

API Send

ระบบเดิม

จะแยกการส่งเป็นแต่ละแบบ โดยใช้ url method ดังนี้

ประเภท

URL Method

Single textual message ส่งข้อความแบบเดียว 1 เบอร์ - หลายเบอร์

https://api2.ants.co.th/sms/1/text/single

Multiple textual message ส่งหลายรูปแบบข้อความและหลายเบอร์ พร้อมกัน

https://api2.ants.co.th/sms/1/text/multi

Fully featured textual message เหมือนกับ Multiple textual message แต่เพิ่ม features ที่หลากหลายมากขึ้น เช่น การกำหนด notify callback , ทำ shorten message,ตั้งเวลาในการส่ง,กำหนด bulkID หรือ messageId จากผู้ใช้งานได้

https://api2.ants.co.th/sms/1/text/advanced

ระบบใหม่

รวบรวม ทุกรูปแบบการส่ง ของทุก features ไว้ในแบบเดียว โดยใช้ Url method : https://api-service.ants.co.th/sms/send

Body Request

ระบบเดิมจะใช้ โครงสร้าง body แต่ละ แบบ แตกต่างกัน

ระบบใหม่ใช้ โครงสร้างเดียวกันหมดและยังสามารถเพิ่ม/ลด parameter(features) ได้ตามความต้องการ

Single textual message

ระบบเดิม

{	"from":"SenderName", 
	"to":[ 
	"66847781470", 
	"66819342499" ],
	 "text": "Message text", 
} 

ระบบใหม่

{"messages":[
	{"from":”SenderName",
	"destinations":[ 
		{"to":"66847781470"},
    {"to":"66819342499"},
	],
	"text":"Message text"}
 ]}

Multiple textual message

ระบบเดิม

{"messages":[ 
              { "from":"SenderName1",  
                  "to":[ "66924482345", "66813457132" ],
               "text":"Message text 1"},
              {"from":"SenderName2", 
                 "to":"66812345678", 
               "text":"Message text 2" 
} ] 
} 

ระบบใหม่

{"messages":[
						 {"from":”SenderName1",
							"destinations":[ 
															{"to":"66924482345"},
															{"to":"66813457132"},],
											"text":"Message text1"},
             {"from":”SenderName2",
             	"destinations":[ 
															{"to":"66812345678"}],
											"text":"Message text2"},
 ]}

Fully featured textual message

ระบบเดิม

{
    "bulkId": "BULK-ID-123-xyz",
    "messages": [
        {
            "from": "Sendname1",
            "destinations": [
                {
                    "to": "66928889988",
                    "messageId": "MESSAGE-ID-123-xyz"
                },
                {
                    "to": "66923801234"
                }
            ],
            "text": "Message Text 1",
            "notifyUrl": "http://www.example.com/sms/advanced",
            "notifyContentType": "application/json",
        },
        {
            "from": "ANTS",
            "destinations": [
                {
                    "to": "66869909988"
                }
            ],
            "text": "Message Text2 url http://domainname.com?parameter=111",
            "sendAt": "2015-07-07T17:00:00.000+01:00"
        }
    ],
    "tracking": {
        "track": "SMS",
        "type": "MY_CAMPAIGN"
    }
}

ระบบใหม่

{
    "bulkId": "BULK-ID-123-xyz",
    "messages": [
        {
            "from": "Sendname1",
            "destinations": [
                {
                    "to": "66928889988",
                    "messageId": "MESSAGE-ID-123-xyz"
                },
                {
                    "to": "66923801234"
                }
            ],
            "text": "สวัสดี Hello Word ",
            "shorturl": "n",
            "notifyUrl": "https://testSend/notify",
            "notifyContentType": "application/json",
            "sendAt":"07/07/2015 17:00"
        },
        {
            "from": "ANTS",
            "destinations": [
                {
                    "to": "66869909988"
                }
            ],
            "text": "Message Text2 url http://domainname.com?parameter=111",
            "sendAt":"07/07/2015 17:00"
        }
    ]
}

ในกรณีที่ลูกค้า ไม่ได้ใช้งาน Features optional อื่นๆ เช่น bulkId = กำหนดชื่อ ID ของ Bulk แคมเปญ messageId = กำหนด ID ของแต่ละหมายเลข shorturl = ให้ระบบย่อ link ที่อยู่ใน message notifyUrl = end point สำหรับ callback แจ้งผลการส่ง notifyContentType = รูปแบบ content ที่ต้องการให้ระบบส่งไป สามารถเลือกได้แบบ json หรือ xml sendAt = ตั้งเวลาให้ระบบส่ง SMS ผู้ใช้งาน ไม่จำเป็นต้องระบุ parameter (features) ที่ไม่ต้องการใช้งาน ระบบจะทำการ detect ตามค่าพื้นฐาน default ให้โดยอัตโนมัติ

Body Response

ระบบเดิม

{
    "messages": [
        {
            "to": "66959394067",
            "status": {
                "groupId": 1,
                "groupName": "PENDING",
                "id": 7,
                "name": "PENDING_ENROUTE",
                "description": "Message sent to next instance"
            },
            "messageId": "28933816647002651819",
            "smsCount": 1
        }
    ]
}

ระบบใหม่

{
    "bulkId": "130d8120-af45-4868-a4fe-39b645679090",
    "details": [
        {
            "messageId": "6ee19547-25b4-473f-80e6-1325411db8ee",
            "to": "66959394067",
            "from": "ANTS",
            "credit": 1,
            "shorturl": "N",
            "status": {
                "code": "101",
                "name": "PENDING",
                "description": "Pending -Message has been accepted by the system"
            }
        }
    ]
}

Last updated

Was this helpful?