Hi, I have configured the Traccar SMS Gateway and configured Traccar to work accordingly.
I want to use the Traccar SMS Gateway and its API to my custom applications also. Its supper cheap than Bulk SMS provider.
is this possible to do with Traccar SMS Gateway? This would be such a nice thing for me if this is possible.
Below is my sample code.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$phone = $_POST['phone'];
$message = $_POST['message'];
$apiUrl = "http://**.130.195.223:8082/sms";
$authorizationToken = "*******************************************";
$data = [
"to" => $phone,
"message" => $message,
"token"=>$authorizationToken
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
if (curl_errno($ch)) {
$error = "Error: " . curl_error($ch);
} else {
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result = "Status Code: $httpCode<br>Response: $response";
}
curl_close($ch);
}
?>
Is there any Api documentation for this? I couldn't find it anywhere
Hi Anton, Thankyou for the response. I tried multiple ways. While, the same settings work perfectly fine for the traccar, it does not work when I use postman or PHP code like I attached above.
Here are some specific questions I had:
- What is the Endpoint to post? It should be possible to post directly on the API exposed by the Mobile App, and also to the API exposed by the traccar? What are those different endpoints?
- How should the request be authenticated. I am aware of the token. But how should the token be used? Should it be sent as a bearer token in the header, or as a payload in the body?
I recommend just inspecting the request Traccar is sending.
Hi, I have configured the Traccar SMS Gateway and configured Traccar to work accordingly.
I want to use the Traccar SMS Gateway and its API to my custom applications also. Its supper cheap than Bulk SMS provider.
is this possible to do with Traccar SMS Gateway? This would be such a nice thing for me if this is possible.
Below is my sample code.
<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // Retrieve input from the form $phone = $_POST['phone']; $message = $_POST['message']; // API URL and Authorization Token $apiUrl = "http://**.130.195.223:8082/sms"; $authorizationToken = "*******************************************"; // Data payload using the template $data = [ "to" => $phone, "message" => $message, "token"=>$authorizationToken ]; // Initialize cURL $ch = curl_init(); // Set cURL options curl_setopt($ch, CURLOPT_URL, $apiUrl); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // Execute the request $response = curl_exec($ch); // Handle errors or display response if (curl_errno($ch)) { $error = "Error: " . curl_error($ch); } else { $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $result = "Status Code: $httpCode<br>Response: $response"; } // Close cURL session curl_close($ch); } ?>