How to send SMS command via API

Victor Butler3 years ago

Hi Anton,

Need your advice on what payload I should send via API in order to send SMS command to a device.

Currently, with the code below, I can send a HEX command to the device via server (command appears in the logs) but I need to modify this code to send the same command as SMS:

API call:

headers['content-type'] = "application/json";
    final response = await http.post(
        Uri.parse(serverURL + "/api/commands/send"),
        body: string,
        headers: headers
    );

Confing file:

<entry key='sms.http.url'>SMS Gateway URL</entry>
<entry key='sms.http.authorization'>TOKEN</entry>
<entry key='sms.http.template'>
    {
        "to": "{phone}",
        "message": "{message}"
    }
</entry>

Please, note if I dispatch the same command via traccar web interface as custom command and I select "Send via SMS" checkbox, the SMS is sent and the device receives it. So I believe the config is correct and instead I should modify the API call above to "request" an SMS send method instead of server one.

Anton Tananaev3 years ago

Have you checked what the official web app is sending? It uses the same API.

Victor Butler3 years ago

Is there a way to actually check the payload sent by web app?

I was looking at the Command model here

I see this code TYPE_SEND_SMS = "sendSms"; but not sure if this is the right parameter and how to embed it in the API call.

Anton Tananaev3 years ago

You can see all network requests in a browser developer tools.

Victor Butler3 years ago

Good advice, it's so simple that I must bang my head repeatedly for not figuring this out yet.

So the answer is textChannel = true for SMS and textChannel = false for server command.

Thank you for the help, really appreciate your commitment to the project!