Phone Local Service

RDHITa year ago

Hello,

There must be something I'm missing. When running the local service on the phone, I'm getting a http POST response as "Unauthorized." Is this app free to use the local API or is that a subscription. Also, is there a way to pass the "to" and "message" content in just a URL? Thanks.

Anton Tananaeva year ago

I think you forgot to provide some context. What local service are you talking about?

RDHITa year ago

Settings>>Gateway Configuration>>Enable Service

Anton Tananaeva year ago

Are you talking about the Traccar SMS Gateway app? The app is completely free. You don't need any subscription. If you get "Unauthorized", it means you simply misconfigured something.

RDHITa year ago

That's what I thought. I'm trying to follow your instructions but I'm lost.

            var values = new Dictionary<string, string>
            {             
                { "to", "+10000000000" },
                { "message", "This is a test." }
            };

            var data = new FormUrlEncodedContent(values);

            var url = "http://[ipaddress]:8082/";
            using var client = new HttpClient();

            var response = await client.PostAsync(url, data);

            string result = response.Content.ReadAsStringAsync().Result;

I'm using C# and still pretty novice. Is this something you can help with?

Anton Tananaeva year ago
  1. Why are you sending form instead of JSON?
  2. Where do you set the API key and how do you send it?
RDHITa year ago

Ah, see total user error. So...

  1. I thought it was serialized as JSON.
  2. The example given by the app at the ip says...
    Send SMS using following API:
    POST /
    {
        "to": "+10000000000",
        "message": "Your message"
    }

...nothing about the API key, which I thought was strange.
I have another example I was working with which serializes the JSON. I'll post; give me minute.

Anton Tananaeva year ago

You should probably check what Traccar sends and compare it. Obviously you need a key. The key is clearly displayed in the app. I'm not sure how you missed it.

RDHITa year ago

What is the "name" of the token/key? How should I reference it?

RDHITa year ago

This passes the API key and still "Unauthorized"...

            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://[ip address]:8082/");
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = "{\"token\":\"The Token\"," +
                              "\"to\":\"10000000000\"}" +
                              "\"message\":\"This is a test.\"}";

                streamWriter.Write(json);
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
            }
Anton Tananaeva year ago

Looks like you're just making stuff up now. Why did you add token attribute to JSON? It should be passed as a standard Authorization header.

RDHITa year ago

Ah, I guess we're getting closer then. I don't understand "standard Authorization header." Can you give example?

Anton Tananaeva year ago
RDHITa year ago

So is it a Basic, Digest, Negotiate and AWS4-HMAC-SHA256? I'm really hoping we can get this working. My company might be interested in purchasing the advanced features.

            string json = "{\"Authorization\":\"Basic [The Token]\"," +
                                 "\"to\":\"10000000000\"}" +
                                 "\"message\":\"This is a test.\"}";

This one didn't work.

Anton Tananaeva year ago

It seems like you are lacking very basic knowledge of APIs. You should probably do some reading first.

As for purchasing features, you can email support if you're interested.