how to send alarm 'lowBattery' thru API

Primtek7 years ago

I am trying to send alarm=lowBattery thru API .. but it always returns 'Bad Request' .. what I missed?..
I configured notification and link to device with attribute name alarm and value 'lowBattery'
need help

try
{
    string url = "http://mydomain.com:8082/api/notifications/caa82be389bf09af" ;
    int id = 2; string type = "Alarms"; bool always = false; bool web = true; bool mail = true; bool sms = false; object attribute = null;

    var data = new
    {
        id = id,
        type = type,
        always = always,
        web = web,
        mail = mail,
        sms = sms,
        attribute = attribute
    };

    var byteArray = Encoding.ASCII.GetBytes(email + ":" + password);

    var client = new HttpClient();
    client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type","application/json");
    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

    var response = client.PutAsync(url, data.AsJson()).Result;   // always return Bad Request here!
    HttpStatusCode statusCode = response.StatusCode;
Anton Tananaev7 years ago

I already gave you one warning. If you continue to ask questions without reading documentation I would have to ban you from this forum. What you are doing with this code makes no sense whatsoever.