Este artículo es una guía sencilla sobre cómo utilizar la API de CLUe para recuperar registros de eventos del servidor CLUe.


Los siguientes ejemplos utilizan ejemplos de cURL y C# WPF .NET.




TABLA DE CONTENIDO

Requisito previo

Acceso

Recuperar registros

Aplicación de muestra



Requisito previo

Para utilizar CLUe API, debe tener la siguiente información.


El PlaceID 

Información Entrar

Token de acceso API: se obtiene iniciando sesión en CLUe.



Acceso

Para utilizar CLUe API, debe tener un token de acceso.


Este token de acceso se puede obtener iniciando sesión en CLUe con su información de inicio de sesión.




1. Llamada API y parámetros

[POST] https://api.moon.supremainc.com/v1/accounts/login/phone


2. Request Body

Please request below information from your Suprema Agent.

FieldTypeRequiredDescription
countryCode
stringyescountry code
phonestringyeslogin id
passwordstringyespassword
accountTypestringyesaccount type
authDeviceTypestringyesauthentication device type


curl --location 'https://api.moon.supremainc.com/v1/accounts/login/phone' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --data '{  "countryCode" : "kr",  "phone" : "0123456789",  "password" : "Pa$sw0rd",  "accountType" : "BUSINESS_OWNER",  "authDeviceType" : "MOBILE_APP" }
'
HTML



3. Respuesta


FieldTypeNullableDescription
code
Number
false
API response code
status
Boolean
false
API response status
message
String
false
API response message
data.accountId
Number
false
account id
data.accountType
String
false
USER / 
SUPREMA_MANUFACTURE / 
SERVICE_PROVIDER/ 
SERVICE_OPERATOR / 
BUSINESS_PROVIDER/ 
BUSINESS_OWNER
data.accountStatus
String
false
INACTIVE
ACTIVE
AUTH_CODE_LOCKED
AUTH_CODE_TOO_MANY_SEND
PASSWORD_LOCKED
PASSWORD_EXPIRED
DELETE_RESERVE
data.name
String
false
account name
data.countryCode
String
false
account countryCode
data.phone
String
false
account phone number
data.accessToken
String
false
API accessToken
data.refreshToken
String
false
API refreshToken

 

HTTP/1.1 200 OK Vary: Origin Vary: Access-Control-Request-Method Vary: Access-Control-Request-Headers Content-Type: application/json Content-Length: 626 {  "code" : 200,  "status" : true,  "message" : "OK",  "data" : {    "accountId" : 1,    "accountType" : "BUSINESS_OWNER",    "accountStatus" : "ACTIVE",    "name" : "diaz",    "countryCode" : "kr",    "phone" : "01234567890",    "accessToken" : "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0dGMiOiJhYyIsImR0YyI6Im1hIiwiZXhwIjoxNjcwODA3ODUzLCJyaWMiOjEsImlhdCI6MTY3MDgwNDI1M30.i-jEiLGExOQGotdy-VGEmDx45gV4LtVJ_waoH18sfog",    "refreshToken" : "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0dGMiOiJyZSIsImR0YyI6Im1hIiwiZXhwIjoxNzAyMzQwMjUzLCJyaWMiOjEsImlhdCI6MTY3MDgwNDI1M30.2idXYbteVFfFDSnYecM3QpW5KBHERrEIx3kZX0L77hw"  } }
HTML


El punto importante aquí es obtener el token de acceso del cuerpo de la respuesta y utilizar este valor como encabezado de autorización en otras llamadas API.



4. Código ejemplo C#


static async Task<string> LoginTask()
{    sAccessToken = null;    string jsonRequestBody = "{";    jsonRequestBody += "\"countryCode\" : \"" + sCountryCode + "\",";    jsonRequestBody += "\"phone\" : \"" + sPhone + "\",";    jsonRequestBody += "\"password\" : \"" + sPassword + "\",";    jsonRequestBody += "\"accountType\" : \"" + sAccountType + "\",";    jsonRequestBody += "\"authDeviceType\" : \"" + sAuthDeviceType + "\"}";
    using (HttpClient client = new HttpClient())    {        string apiUrl = "https://api.moon.supremainc.com/v1/accounts/login/phone";
        // Set the JSON content        StringContent content = new StringContent(jsonRequestBody, Encoding.UTF8, "application/json");        HttpResponseMessage response = await client.PostAsync(apiUrl, content);                if (response.IsSuccessStatusCode)        {            string responseBody = await response.Content.ReadAsStringAsync();            sLoginResponse = responseBody;            var loginResponse = LoginResponse.FromJson(responseBody);            sAccessToken = loginResponse.Data.AccessToken;        }        else        {            string responseBody = await response.Content.ReadAsStringAsync();            var clueErrorResponse = ClueErrorResponse.FromJson(responseBody);            string errorResponse = clueErrorResponse.Errors[0].Code + ":" + clueErrorResponse.Errors[0].Message;            MessageBox.Show("失敗しました。\n" + errorResponse, "Error");        }    }    return sAccessToken;
}
C
sAccessToken = el token de acceso recuperado del cuerpo de la respuesta




Obtener Logs


1. Llamada API y parámetros

[GET] https://api.moon.supremainc.com/v1/events/places/:placeId


Request Header:

KeyTypeRequiredDescription
Authorization
JWT TokenyesAccess Token retrieved from Login API


Path Variables:

KeyTypeRequiredDescription
placeId
NumberyesThe assigned placeID of your store.
Please request information from Suprema Agent.


Query Parameter:

KeyTypeRequiredDescription
startTime
Unix Time (Millisec)noretrieve logs starting this date
if not specified, all logs are displayed
endTimeUnix Time (Millisec)noretrieve logs until this date
if not specified, all logs are displayed
filterEventsstringnodisplay only events with the specified event type.
if not specified, all logs are displayed
pageNumbernologs are displayed in multiples pages.
if not specified, displayed in 1 page only.
sizeNumbernonumber of logs to be retirieved from the startTime
sortstringnosort the logs by ID in ascending ('asc') or descending ('desc') order
Example: id%2Cdesc


curl --location 'https://api.moon.supremainc.com/v1/events/places/178?startTime=1675124016000&endTime=1703981616000&filterEvents=DEV_FACE_AUTH_SUCCESS&page=0&size=256&sort=id%2Cdesc' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0dGMiOiJhYyIsImR0YyI6Im1hIiwiZXhwIjoxNjk0NzM1OTkxLCJyaWMiOjM1LCJpYXQiOjE2OTQ3MzIzOTF9.yH_Fc7j4CDHEMNVoDdstakVNqtYbkXTN5-JFM3tgaJY'
HTML



2. Cuerpo de llamada

Ninguno


3. Respuesta

 

FieldTypeNullableDescription
code
Number
false
API response code
status
Boolean
false
API response status
message
String
false
API response message
totalNumberfalsetotal number of retrieved logs.
data.logIdNumberfalseCLUe server side's log ID.
data.eventAtUnix TimefalseDate and time when the event occurred.
data.placeIdNumberfalsePlace ID
data.deviceIdNumbertrueDevice ID
data.doorIdNumbertrueDoor ID
data.doorNameStringtrueDoor Name
data.authIdNumbertrueAuthentication ID
data.userIdNumbertrueUser Key
data.useNameStringtrueUser Name
data.localLogIdNumberfalseDevice side's log ID
data.eventTypeEvent Typefalseevent type

 

HTTP/1.1 200 OK Vary: Origin Vary: Access-Control-Request-Method Vary: Access-Control-Request-Headers Content-Type: application/json Content-Length: 634 {
{    "code": 200,    "status": true,    "message": "OK",    "total": 507,    "data": [        {            "logId": 12907987,            "eventAt": 1694066002529,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4607,            "eventType": "DEV_DOOR_RELAY_OFF"        },        {            "logId": 12907979,            "eventAt": 1694065999512,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4606,            "eventType": "DEV_DOOR_RELAY_ON"        },        {            "logId": 12907978,            "eventAt": 1694065999471,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "authId": 8744,            "doorName": "testDoor",            "userId": "12345678",            "userName": "EBISU",            "localLogId": 4605,            "eventType": "DEV_FACE_AUTH_SUCCESS"        },        {            "logId": 12907965,            "eventAt": 1694065996127,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4604,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907955,            "eventAt": 1694065992829,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4603,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907951,            "eventAt": 1694065989790,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4602,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907946,            "eventAt": 1694065986920,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4601,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907942,            "eventAt": 1694065983825,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4600,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907937,            "eventAt": 1694065980832,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4599,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907933,            "eventAt": 1694065977903,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4598,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907924,            "eventAt": 1694065974147,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4597,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907915,            "eventAt": 1694065969479,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4596,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907880,            "eventAt": 1694065948852,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4595,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907853,            "eventAt": 1694065943870,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4594,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907837,            "eventAt": 1694065940445,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4593,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907831,            "eventAt": 1694065937586,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4592,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12907819,            "eventAt": 1694065926868,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4591,            "eventType": "DEV_FACE_AUTH_FAIL"        },        {            "logId": 12905071,            "eventAt": 1694063933649,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4590,            "eventType": "DEV_DOOR_RELAY_OFF"        },        {            "logId": 12905069,            "eventAt": 1694063930647,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4589,            "eventType": "DEV_DOOR_RELAY_ON"        },        {            "logId": 12905066,            "eventAt": 1694063930569,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "authId": 8744,            "doorName": "testDoor",            "userId": "12345678",            "userName": "EBISU",            "localLogId": 4588,            "eventType": "DEV_FACE_AUTH_SUCCESS"        },        {            "logId": 12905065,            "eventAt": 1694063930492,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4587,            "eventType": "DEV_DOOR_RELAY_OFF"        },        {            "logId": 12905064,            "eventAt": 1694063927477,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4586,            "eventType": "DEV_DOOR_RELAY_ON"        },        {            "logId": 12905062,            "eventAt": 1694063927452,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "authId": 8744,            "doorName": "testDoor",            "userId": "12345678",            "userName": "EBISU",            "localLogId": 4585,            "eventType": "DEV_FACE_AUTH_SUCCESS"        },        {            "logId": 12905060,            "eventAt": 1694063924568,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4584,            "eventType": "DEV_DOOR_RELAY_ON"        },        {            "logId": 12905058,            "eventAt": 1694063924490,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "authId": 8744,            "doorName": "testDoor",            "userId": "12345678",            "userName": "EBISU",            "localLogId": 4583,            "eventType": "DEV_FACE_AUTH_SUCCESS"        },        {            "logId": 12905055,            "eventAt": 1694063921597,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4582,            "eventType": "DEV_DOOR_RELAY_ON"        },        {            "logId": 12905052,            "eventAt": 1694063921556,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "authId": 8744,            "doorName": "testDoor",            "userId": "12345678",            "userName": "EBISU",            "localLogId": 4581,            "eventType": "DEV_FACE_AUTH_SUCCESS"        },        {            "logId": 12904676,            "eventAt": 1694063600474,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4580,            "eventType": "DEV_DOOR_RELAY_OFF"        },        {            "logId": 12904672,            "eventAt": 1694063597477,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4579,            "eventType": "DEV_DOOR_RELAY_ON"        },        {            "logId": 12904671,            "eventAt": 1694063597440,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "authId": 8744,            "doorName": "testDoor",            "userId": "12345678",            "userName": "EBISU",            "localLogId": 4578,            "eventType": "DEV_FACE_AUTH_SUCCESS"        },        {            "logId": 12904667,            "eventAt": 1694063594788,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4577,            "eventType": "DEV_DOOR_RELAY_ON"        },        {            "logId": 12904664,            "eventAt": 1694063594753,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "authId": 8744,            "doorName": "testDoor",            "userId": "12345678",            "userName": "EBISU",            "localLogId": 4576,            "eventType": "DEV_FACE_AUTH_SUCCESS"        },        {            "logId": 12904657,            "eventAt": 1694063590253,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4575,            "eventType": "DEV_DOOR_RELAY_OFF"        },        {            "logId": 12904651,            "eventAt": 1694063587211,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4574,            "eventType": "DEV_DOOR_RELAY_ON"        },        {            "logId": 12904650,            "eventAt": 1694063587143,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "authId": 8173,            "doorName": "testDoor",            "userId": "34567",            "userName": "Jack",            "localLogId": 4573,            "eventType": "DEV_FACE_AUTH_SUCCESS"        },        {            "logId": 12904640,            "eventAt": 1694063580664,            "placeId": 178,            "deviceId": 902,            "doorId": 181,            "localLogId": 4572,            "eventType": "DEV_FACE_AUTH_FAIL"        }    ] }
}
HTML



4. Código ejemplo en C#


static async Task<string> GetLogEvents( string placeID, int numOfLogs )
{    using (HttpClient client = new HttpClient())    {        string apiUrl = sApiEndpoint + "/v1/events/places/" + placeID + "?size=" + numOfLogs + "&sort=id%2Cdesc";        string authHeader = "Bearer " + sAccessToken;
        CookieContainer cookieContainer = new CookieContainer();        HttpClientHandler handler = new HttpClientHandler        {            CookieContainer = cookieContainer        };
        // Set the JSON content        client.DefaultRequestHeaders.Add("Authorization", authHeader);        cookieContainer.Add(new Uri(sApiEndpoint), new Cookie("Authorization", authHeader));
        HttpResponseMessage response = client.GetAsync(apiUrl).Result;
        if (response.IsSuccessStatusCode)        {            string responseBody = await response.Content.ReadAsStringAsync();            sLogEventResponse = responseBody;        }        else        {            string responseBody = await response.Content.ReadAsStringAsync();            var clueErrorResponse = ClueErrorResponse.FromJson(responseBody);            string errorResponse = clueErrorResponse.Errors[0].Code + ":" + clueErrorResponse.Errors[0].Message;            MessageBox.Show("c。\n" + errorResponse, "Error");        }    }    return sLogEventResponse;
}
C
sLogEventResponse = contains the entire API response body in JSON format. You can then convert this JSON string to Array or List<>.



Aplicación de Prueba


Explicación

  1. DEV_FACE_AUTH_SUCCESS - La plantilla de rostro del usuario está registrada en el servidor CLUe. Por lo tanto, es exitoso cuando el usuario se autentica desde el dispositivo.
  2. VENDOR_AUTH_SUCCESS - Significa que el ID del usuario (ejemplo 64455 anterior) está registrado y se le permite el acceso desde el sistema de terceros.
  3. DEV_DOOR_RELAY_ON - .El relé del dispositivo está encendido. La puerta está desbloqueada
  4. DEV_DOOR_RELAY_OFF - El relé del dispositivo está apagado. La puerta está cerrada.


Sample Flow of Events for Authentication Success


Sample Flow of Events for Authentication Failed (CLUe Side)


Sample Flow of Events for Authentication Failed (3rd Party System side)