Sending SMS to device.

Gerard Iscala 2 years ago

Hello, your help please.

I am trying to configure the 1NCE API to send SMS to the devices and it works correctly in the following way.

traccar.xml file

 <entry key='notificator.types'>traccar,Command,web,sms,mail</entry>
 <entry key='sms.http.url'>https://api.1nce.com/management-api/v1/sims/8988228066603276428/sms</entry>
 <entry key='sms.http.method'>POST</entry>
 <entry key='sms.http.authorization'>Bearer rtyewqasddeyJpZHRva2VuIjoiZXlKcmFXUWlPaUpVWlVkeWVqbExkbEJdfrhnjukfvgrfkkjjuyy</entry>
 <entry key='sms.http.template'>
 {
 "source_address": "12345678",
 "payload": "{message}"
 }
 </entry>

but I need to make it dynamic that depends on the device that selects to send the command by SMS and take the {phone} variable that each device has configured. The following way does not work, help me how I can add the {phone} variable to the api url.
traccar.xml file

 <entry key='notificator.types'>traccar,Command,web,sms,mail</entry>
 <entry key='sms.http.url'>https://api.1nce.com/management-api/v1/sims/{phone}/sms</entry>
 <entry key='sms.http.method'>POST</entry>
 <entry key='sms.http.authorization'>Bearer rtyewqasddeyJpZHRva2VuIjoiZXlKcmFXUWlPaUpVWlVkeWVqbExkbEJdfrhnjukfvgrfkkjjuyy</entry>
 <entry key='sms.http.template'>
 {
 "source_address": "12345678",
 "payload": "{message}"
 }
 </entry>

Your help please

Anton Tananaev 2 years ago

Placeholders are not supported in the URL, as far as I remember.

Gerard Iscala 2 years ago

Sorry, I don't understand the answer, or I didn't make myself understood.

Currently with this code it works perfectly for me.

 <entry key='notificator.types'>traccar,command,web,sms,mail</entry>
 <entry key='sms.http.url'>https://api.1nce.com/management-api/v1/sims/8988228066603276428/sms</entry>
 <entry key='sms.http.method'>POST</entry>
 <entry key='sms.http.authorization'>Bearer rtyewqasddeyJpZHRva2VuIjoiZXlKcmFXUWlPaUpVWlVkeWVqbExkbEJdfrhnjukfvgrfkkjjuyy</entry>
 <input key='sms.http.template'>
 {
 "source_address": "12345678",
 "payload": "{message}"
 }
 </entry>

But I want to add the phone variable that each device has. The 1nce API requires the phone number to be specified in the url <entry key='sms.http.url'>https://api.1nce.com/management-api/v1/sims/{phone}/sms< /entry> this way java throws me a variable error.

Gerard Iscala 2 years ago

Tracar generates the following error when sending the command via SMS.

The template variable 'phone' has no value - IllegalArgumentException (... < HttpSmsClient:87 < *:96 < BaseProtocol:127 < CommandsManager:82 < ...)

my traccar.xml file

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE properties SYSTEM 'http://java.sun.com/dtd/properties.dtd'>
<properties>

 <!-- Documentation: https://www.traccar.org/configuration-file/ -->

 <entry key='database.driver'>com.mysql.cj.jdbc.Driver</entry>
 <entry key='database.url'>jdbc:mysql://localhost/traccar?zeroDateTimeBehavior=round&amp;serverTimezone=UTC&amp;allowPublicKeyRetrieval=true&amp;useSSL=false&amp;allowMultiQueries=true&amp;autoReconnect=true&amp;useUnicode=yes&amp;characterEncoding= UTF-8&amp;sessionVariables=sql_mode=''</entry>
 <entry key='database.user'>user</entry>
 <entry key='database.password'>password</entry>

 <entry key='notificator.types'>traccar,Command,web,sms,mail</entry>
 <entry key='sms.http.url'>https://api.1nce.com/management-api/v1/sims/{phone}/sms</entry>
 <entry key='sms.http.method'>POST</entry>
 <entry key='sms.http.authorization'>Bearer rettvtveyJpZHRva2jgfcdddsddggvrwqaertubhhgfdsbcefy</entry>
 <entry key='sms.http.template'>
 {
 "source_address": "12345678",
 "payload": "{message}"
 }
 </entry>

</properties>
Anton Tananaev 2 years ago

... not supported ...

Baxtiyor a year ago

Hallo everyone.
I want use traccar programm for sending sms gateway.

JSON Data: {"to":"+998333346767","message":"This is a test SMS from Traccar SMS Gateway!"}
Response Status: 401 Unauthorized
Error sending SMS: HTTP response error: status code 401 - 401 Unauthorized
exit status 1

But this problem

Anton Tananaev a year ago

The error code is telling you what the problem is.

Baxtiyor a year ago

Is there documentation for authorization?

Anton Tananaev a year ago

No, but you just need to send token in the authorization header.

Baxtiyor a year ago
req, err := http.NewRequest("POST", "http://192.168.1.188:8082/sms", bytes.NewBuffer(jsonData))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error creating request: %v\n", err)
		os.Exit(1)
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer 933c4615-ba2f-4fcc-be29-a619f800a5db")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		fmt.Fprintf(os.Stderr, "HTTP request error: %v\n", err)
		os.Exit(1)
	}
	defer resp.Body.Close()

It is true?

Anton Tananaev a year ago

I don't think you need Bearer. I also realized that your question is completely unrelated to the original discussion. Please find the right place to ask questions.

Dsuarez a year ago

Hi gerard,

Did you find any solution to send messages to 1NCE sim cards?

Peek a year ago

nudge...