This API is authenticated by using Bearer Token authentication for each endpoint request. The HTTP client must send this token in the Authorization header when making requests to protected resources:
Authorization: Bearer [API_TOKEN]
For example, your authentication header will look something like this:
Authorization: Bearer 8d162cc813ce4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
API token is set per device. You can get your token by the steps:
There are 2 types of rate limits:
This endpoint is to retrieve the status of the device.
GET https://onsend.io/api/v1/status
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://onsend.io/api/v1/status',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_POSTFIELDS => '',
CURLOPT_HTTPHEADER => [
'Accept: application/json',
'Authorization: Bearer [API_TOKEN]',
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
<?php
$response = \Illuminate\Support\Facades\Http::accept('application/json')
->withToken('[API_TOKEN]')
->get('https://onsend.io/api/v1/status');
dump($response->body());
curl --header "Accept: application/json" \
--header "Authorization: Bearer [API_TOKEN]" \
https://onsend.io/api/v1/status
Send a message to specified receiver.
POST https://onsend.io/api/v1/send
Attribute | Description |
---|---|
phone_number | string required Intended phone number of the message receiver with country code. Example: 60123456789 |
message | string required IF user wants to send text message only Text message to be sent. Sent as caption if an image or video is sent. Example: Hello world |
type | string required Type of message to send. Can be either text, image, video, or document . Example: image |
url | string required IF user wants to send media [image, video, document] The media URL. Currently only suppot URL from live servers. Example: https://example.com/logo.png |
mimetype | string required IF user wants to send document MIME type or media type of the document to be sent. Example: application/pdf |
filename | string optional The file name of document to be sent. Example: invoice.pdf |
{
"phone_number": "60123456789",
"message": "Hello world"
}
{
"phone_number": "60123456789",
"message": "Logo",
"type": "image",
"url": "https://example.com/logo.png"
}
{
"phone_number": "60123456789",
"message": "My video",
"type": "video",
"url": "https://example.com/myvideo.mp4"
}
{
"phone_number": "60123456789",
"type": "document",
"url": "https://example.com/invoice.pdf",
"mimetype": "application/pdf",
"filename": "invoice.pdf"
}
<?php
$curl = curl_init();
$data = [
'phone_number' => '60123456789',
'message' => 'Hello world',
];
curl_setopt_array($curl, [
CURLOPT_URL => 'https://onsend.io/api/v1/send',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => [
'Accept: application/json',
'Authorization: Bearer [API_TOKEN]',
'Content-Type: application/json',
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
<?php
$data = [
'phone_number' => '60123456789',
'message' => 'Hello world',
];
$response = \Illuminate\Support\Facades\Http::accept('application/json')
->withToken('[API_TOKEN]')
->post('https://onsend.io/api/v1/send', $data);
dump($response->body());
curl --header "Accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer [API_TOKEN]" \
--request POST \
--data '{"phone_number":"60123456789","message":"Hello world"}' \
https://onsend.io/api/v1/send