SMS API

asdfrg5t3 days ago

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);
}
?>
Anton Tananaev2 days ago

Should be possible.

asdfrg5t2 days ago

Is there any Api documentation for this? I couldn't find it anywhere

Anton Tananaev2 days ago
asdfrg5t15 hours ago

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:

  1. 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?
  2. 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?
Anton Tananaev15 hours ago

I recommend just inspecting the request Traccar is sending.