I think you forgot to provide some context. What local service are you talking about?
Settings>>Gateway Configuration>>Enable Service
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.
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?
Ah, see total user error. So...
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.
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.
What is the "name" of the token/key? How should I reference it?
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();
}
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.
Ah, I guess we're getting closer then. I don't understand "standard Authorization header." Can you give example?
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.
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.
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.