kwtsms.com_api_documentation_v37 (3)
kwtsms.com_api_documentation_v37 (3)
API Documentation
HTTP/REST (JSON)/SMTP
2024/01/25 - v3.7
1. Requirements
2. Register Account
3. Features
4. HTTP API
a. balance
b. senderid
c. dlr
d. send
5. REST API
a. balance
b. senderid
c. dlr
d. send
6. SMTP API
7. Error Codes
8. Implementation Best Practices
9. FAQs
10. Sample Code
a. PHP
b. Python
c. NODE.js
11. Change Log
API Use
You need username and password for API calls
Do not use your mobile number as username, it will not work!
You can find it in your kwtSMS.com account API page, after it is enabled
IMPORTANT NOTE
HTTP Headers for Content-Type and Accept must be set to: text/html
HTTP Method: POST
Balance command:
This command is used to retrieve the account balance and total purchased credits.
URL: https://www.kwtsms.com/API/balance/
Balance parameters:
Variable Type #Chrs Mandatory Description
username Alphanumeric 15 Yes API Username
password Alphanumeric 30 Yes API password
Sample output:
181.00/1000.00
Senderid command:
This command is used to retrieve all available senderids that can be used in the (send) command.
URL: https://www.kwtsms.com/API/senderid/
Senderid parameters:
Variable Type #Chrs Mandatory Description
username Alphanumeric 15 Yes API Username
password Alphanumeric 30 Yes API password
Sample output:
KWT-SMS
KWT-TEST
URL: https://www.kwtsms.com/API/dlr/
DLR parameters:
Variable Type Max Mandatory Description
username Alphanumeric 15 Yes API username
password Alphanumeric 30 Yes API password
msgid Alphanumeric 32 Yes This is a unique msgid that was generated
previously by the API when you sent the
message. So, if you want to check for delivery
reports you must save the message id in your
database.
Sample: output:
xxxxxxxx,Blacklisted
xxxxxxxx,Delivered to mobile
Send command:
This command is used to send SMS messages.
URL: https://www.kwtsms.com/API/send/
Send parameters:
Variable Type #Chrs Mandatory Description
username Alphanumeric 15 Yes API username
password Alphanumeric 30 Yes API password
sender Alphanumeric 11 Yes Use your private senderid or one of ours.
SenderID is case sensitive.
mobile Numeric 2500 Yes ',' comma separated, no '+' or '00' or '.' or
space in numbers, English only (1,2,3,..)
lang Numeric 1 Yes 1: English (ASCII)
2: Arabic (CP1256)
3: Arabic (UTF-8)
4: Unicode
test Numeric 1 No 1 or 0: If set, messages will not be sent to
handsets, but will be inserted to the queue
and can be deleted to recover the credits.
message Alphanumeric - Yes use “\n” for new lines, no html or emoji
Sample output:
OK:f4c841adee210f31307633ceaebff2ec:1:1:180:1242667894
IMPORTANT NOTE
Balance command:
This command is used to retrieve the account balance and total purchased credits.
URL: https://www.kwtsms.com/API/balance/
Balance parameters:
Variable Type #Chrs Mandatory Description
username Alphanumeric 15 Yes API Username
password Alphanumeric 30 Yes API password
Sample output:
{"result":"OK","available":150,"purchased":1000}
Senderid command:
This command is used to retrieve all available senderids that can be used in the (send) command.
URL: https://www.kwtsms.com/API/senderid/
Senderid parameters:
Variable Type #Chrs Mandatory Description
username Alphanumeric 15 Yes API Username
password Alphanumeric 30 Yes API password
Sample output:
{"result":"OK","senderid":[“KWT-SMS","KWT-TEST"]}
URL: https://www.kwtsms.com/API/dlr/
DLR parameters:
Variable Type #Chrs Mandatory Description
username Alphanumeric 15 Yes API username
password Alphanumeric 30 Yes API password
msgid Alphanumeric 32 Yes This is a unique msgid that was generated
previously by the API when you sent the
message. So, if you want to check for delivery
reports you must save the message id in your
database.
Sample: output:
{"result":"OK","report":[{"Number":"xxxxxxxx","Status":"Received by recipient"}]}
Send command:
This command is used to send SMS messages.
URL: https://www.kwtsms.com/API/send/
Send parameters:
Variable Type #Chrs Mandatory Description
username Alphanumeric 15 Yes API username
password Alphanumeric 30 Yes API password
sender Alphanumeric 11 Yes Use your private senderid or one of ours.
SenderID is case sensitive.
mobile Numeric 2500 Yes ',' comma separated, no '+' or '00' or '.' or
space in numbers, English only (1,2,3,..)
lang Numeric 1 Yes 1: English
2: Arabic (CP1256)
3: Arabic (UTF-8)
4: Unicode
test Numeric 1 No 1 or 0: If set, messages will not be sent to
handsets, but will be inserted to the queue
and can be deleted to recover the credits.
message Alphanumeric - Yes use “\n” for new lines, no html or emoji
Sample output:
{"result":"OK","msg-id":"f4c841adee210f31307633ceaebff2ec","numbers":1,"points-
charged":1,"balance-after":180,"unix-timestamp":1684763355}
Needless to say, using this method is very insecure as emails travel though the internet in plain
text and not encrypted.
The email content type should be Text, and not Rich text or HTML.
eMail Parameters:
Variable Type #Chrs Mandatory Description
username Alphanumeric 15 Yes API username
password Alphanumeric 30 Yes API password
sender Alphanumeric 11 Yes Use your private senderid or one of ours.
SenderID is case sensitive.
mobile Numeric 2500 Yes ',' comma separated, no '+' or '00' or '.' or
space in numbers
lang Numeric 1 Yes 1: English
2: Arabic (CP1256)
3: Arabic (UTF-8)
4: Unicode
message Alphanumeric - Yes use “\n” for new lines
The email subject is ignored. The parameter value should be in the same line.
NOTE: If there is anything wrong with your email or parameters or balance your message will not
be sent and you will not get error message.
1. PHP
<?php
// Set up API URL and parameters
$url = "https://www.kwtsms.com/API/balance/";
$username = "your_username";
$password = "your_password";
$params = array(
"username" => $username,
"password" => $password
);
Note that we are using cURL to make the HTTP request to the API. This is a common
method for making HTTP requests in PHP. Additionally, we are using SSL verification to
ensure that the API server's SSL certificate is valid and trusted. This is an important
security measure.
Note that We are using the requests library to make the HTTP request to the API. This is a
common method for making HTTP requests in Python. Additionally, we are using SSL
verification to ensure that the API server's SSL certificate is valid and trusted. This is an
important security measure.
const options = {
hostname: 'www.example.com',
port: 443,
path: '/api/balance/',
method: 'POST',
headers: {
'Content-Type': 'text/html'
}
};
res.on('data', d => {
process.stdout.write(d);
});
});
We are using the https module to make the HTTPS request to the API. We set up the
appropriate request options, including the URL and request method, and handle the
response accordingly. We also write the POST data to the request body before ending the
request.
https://www.kwtsms.com/account/api/code/