Log in

Login is the first method that must be used because it is responsible for generating the session used in all requests to the device. The request will create the session and store it in the session variable in this example.

As an example, the login command can have the URL:

 http://192.168.0.129/login.fcgi

and the following parameters:

 {
     login: 'admin',
     password: 'admin'
 }

The return of the login method is a JSON like the example below:

 {
     "session":"apx7NM2CErTcvXpuvExuzaZ"
 }

The following requirements apply to API data requests from the access control devices:

All commands require a valid session, except session_is_valid and login. This session must be reused for all requests you make to the device.

The request body must have UTF-8 encoding. If the characters sent do not have any special characters (ASCII), the request body does not need to be encoded.

By default, the encoding used by Windows systems is Windows-1252 (also known as CP-1252). Check how to use the correct encoding.

Login example in JavaScript

The example below can be used for familiarization using the browser's developer tools:

 $.ajax({
   url: "/login.fcgi",
   type: 'POST',
   contentType: 'application/json',
   data: JSON.stringify({
       login: 'admin',
       password: 'admin'
   }),
   success: function(date) {
       session = data.session;
   }
 });

For more details about login, please check the topic SESSION MANAGEMENT.

Below are some examples illustrating how the API can be used in other programming languages. In these examples, the address 192.168.0.129, when it appears, represents the IP address of the device.

Please note: the HTTP option "Expect: 100- continue" must be disabled for calls to work. The only one of the examples below that does this explicitly is the one in C#. Please check if it is necessary to do it in your preferred language.

Login example in Delphi

procedure TFrmTTWebserviceTester.Button1Click(Sender: TObject);
var
    lJSO : ISuperObject;
    lRequest: TStringStream;
    lResponse: String;
begin
    lJSO := SO('{"login": "admin", "password": "admin"}');
    lRequest := TStringStream.Create(lJSO.AsString, TEncoding.UTF8);
    try
        IdHTTP.Request.ContentType := 'application/json';
        IdHTTP.Request.Charset := 'utf-8';
        try
            lResponse := IdHTTP.Post('http://192.168.0.129/login.fcgi', lRequest);
            ShowMessage(lResponse);
        except
            on E: Exception do
                ShowMessage('Error on request:'#13#10 + E.Message);
        end;
    finally
        lRequest.Free;
    end;
    lJSO := nil;
end;

This Delphi example uses the open-source library Indy.

This manual is intended to assist the user in configuring and operating his device.

Login example in Java

try {
  URL url = new URL("http://192.168.0.129/login.fcgi");
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setRequestMethod("POST");
  conn.setRequestProperty("Content-type", "application/json");
  conn.setDoInput(true);
  conn.setDoOutput(true);

  OutputStream os = conn.getOutputStream();
  os.write("{\"login\":\"admin\",\"password\":\"admin\"}".getBytes());

  if (conn.getResponseCode() != 200) {
  BufferedReader br = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
    String output, result = "";
    System.out.println("Output from Server .... \n");
    while ((output = br.readLine()) != null) {
      result += output;
    }
    throw new RuntimeException("Failed : " + result);
  }

  BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));

  String output;
  System.out.println("Output from Server .... \n");
  while ((output = br.readLine()) != null) {
    System.out.println(output);
  }
  conn.disconnect();
} catch (Exception e) {
  e.printStackTrace();
}

Login example in C#

System.Net.ServicePointManager.Expect100Continue = false;
try
{
  var request = (HttpWebRequest)WebRequest.Create("http://192.168.0.129/login.fcgi");
  request.ContentType = "application/json";
  request.Method = "POST";

  using (var streamWriter = new StreamWriter(request.GetRequestStream()))
  {
    streamWriter.Write("{\"login\":\"admin\",\"password\":\"admin\"}");
  }

  var response = (HttpWebResponse)request.GetResponse();
  using (var streamReader = new StreamReader(response.GetResponseStream()))
  {
    Console.WriteLine(streamReader.ReadToEnd());
  }
}
catch (WebException e)
{
  using (WebResponse response = e.Response)
  {
    HttpWebResponse httpResponse = (HttpWebResponse)response;
    Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
    using (Stream data = response.GetResponseStream())
    using (var reader = new StreamReader(data))
    {
      string text = reader.ReadToEnd();
      Console.WriteLine(text);
    }
  }
}

Login example in C# w/ RestSharp

For the development of this example, the library being used is RestSharp.

using System;
using RestSharp;
namespace ExampleToDevelopment
{
    class Program
    {
        public string Session()
        {
            var client = new RestClient("http://192.168.2.183/login.fcgi");
            var request = new RestRequest(Method.POST);
            request.AddHeader("content-type", "application/json");
            request.AddParameter("application/json", "{\"login\": \"admin\", \"password\": \"admin\"}", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            return response.Content;
        }
    }
}