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.
I ran into something similar and fixed it by using double quotes around the URL and parameters in the config file. Single quotes didn’t work for me, maybe give that a shot.
This simply works: (can be converted to adopt any language).
PHONE="E.164 PHONE NUMBER"
MESSAGE="Your message"
TOKEN="*********************************"
curl -X POST "https://www.traccar.org/sms/" \
-H "Content-Type: application/json" \
-H "Authorization: ${TOKEN}" \
-d "{
\"to\": \"${PHONE}\",
\"message\": \"${MESSAGE}\"
}"
I had the same trouble before, and what worked for me was using a [redacted] to handle sending SMS codes. It’s really easy to set up, and you just call their endpoint with the user’s phone number—no need to build your own full SMS system from scratch. It also handles retries and code expiration so you don’t have to code all of that yourself.
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); } ?>