· 5 years ago · Jul 20, 2020, 08:14 PM
1import http.client
2conn = http.client.HTTPSConnection("https://api.sms.to")
3payload = "{\n \"message\": \"This is test\",\n \"to\": \"+9779856034616\",\n \"sender_id\": \"SMSto\",\n \"callback_url\": \"https://example.com/callback/handler\"\n}"
4headers = {
5 'Content-Type': 'application/json',
6 'Authorization': 'Bearer <YOUR_API_KEY_OR_ACCESS_TOKEN>'
7}
8conn.request("POST", "/sms/send", payload, headers)
9res = conn.getresponse()
10data = res.read()
11print(data.decode("utf-8"))
12
13OR
14// Using API Key via Query Param
15import http.client
16conn = http.client.HTTPSConnection("https://api.sms.to")
17payload = ""
18
19conn.request("POST", "/sms/send?api_key={api_key}&to=9779856034616&message=test&sender_id=smsto", payload, headers)
20res = conn.getresponse()
21data = res.read()
22print(data.decode("utf-8"))
23
24 RESPONSE:
25
26{
27 "message": "Message is queued for sending! Please check report for update",
28 "success": true,
29 "message_Id": "e7745289-7236-497f-acf2-f9cfd6a86f16"
30}