...
When you have retrieved a token with success, then read our suggestions for handling the token.
Authorization
Url: https://air.winkas.net/api/Authentication/Authenticate
...
Code Block | ||
---|---|---|
| ||
{ "AuthenticationMessage": "User successfully authenticated", "WinKasData": { "Id": 3397, "UserName": "", "UserPassword": "", "UserContractCode": "", "CurrentToken": "U1vTDs062o1iadVMJK72-nblIDVDB|86VbN3h7sSiW9QOZMrofSKw|xPE3Y3mHX7tU8U-jI-pZPJTiWlTI8n|nX45nUweWqh89gaPthYa|lTDEDqXc2ISwsoK-aWL9wL1C2rPS1onwa8|j1PouTZjxLi|SdGisCQqspzYy3jerLaUikSS|Q5VrN23a|cIqtxe|HDCOyb5B-CeyjVTkTwTl6yiQ92nkvJq43oSxP7-crg_", "UserRealName": "MJ", "AuthLevel": null, "Profile": null }, "WinkasErrorCode": 0, "WinKasStatus": 0, "WinKasStatusString": "Okay", "WinKasMessage": "Authentication was okay.", "ApiVersion": "5.67.2.1", "ResponseDateTime": "2022-03-21T10:43:26", "ResponseInfo": { "ElapsedSeconds": 0.1, "ServerName": "WINKAS-AIRWEB02" }, "Source": null |
Code example – Authentication.
Below examples for authentication in the following languages:
C#
Javascript / Ajax
Php
ASP (Classic)
C#
Code Block | ||
---|---|---|
| ||
public string GetToken() { var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://air.winkas.net/api/Authentication/Authenticate"); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = new JavaScriptSerializer().Serialize(new { UserName = "xxxxx", UserPassword = "xxxxx", UserContractCode = "xxxxx" }); streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var _jsonAuth = streamReader.ReadToEnd(); dynamic _jsonContent = JsonConvert.DeserializeObject(_jsonAuth); string _token = _jsonContent.WinKasData.CurrentToken; return _token; } } } |
Javascript
Code Block |
---|
$(document).ready(function () { var winkasServer = (function () { var getAccounts = function (request) { return $.ajax( 'https://air.winkas.net/api/Accounts/All', { type: "POST", data: request }); }; var authenticate = function (request) { return $.ajax( 'https://air.winkas.net/api/Authentication/Authenticate', { type: "POST", data: request } ); }; return { getAccounts: getAccounts, authenticate: authenticate }; }()); var el = { btnAction: $('#action'), result: $('#result') }; el.btnAction.on('click', function () { el.result.html("Getting..."); var request = { "UserName": "xxxxx", "UserPassword": "xxxxx", "UserContractCode": "xxxxx" }; winkasServer.authenticate(request).done(function (data) { var token = data.WinKasData.CurrentToken; request = { "Token": token }; winkasServer.getAccounts(request).done(function (accounts) { var acc = accounts.Accounts; var html = ""; for (var i = 0; i < acc.length; i++) { html += acc[i].Number + ", "; } el.result.html(html); }); }); }); }); |
PHP
Code Block |
---|
//create array of data to be posted $post_data['UserName'] = 'xxxxx'; //You should add your test user $post_data['UserPassword'] = 'xxxxx'; //You should add your test password $post_data['UserContractCode'] = 'xxxxx'; //You should add your test account/contract //traverse array and prepare data for posting (key1=value1) foreach ( $post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted using implode() $post_string = implode ('&', $post_items); //create cURL connection $curl_connection = curl_init('https://air.winkas.net/api/Authentication/Authenticate'); //set options curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); //set data to be posted curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); //perform our request $result = curl_exec($curl_connection); //dump result echo ' '; print_r($result); echo ' ------------------------ '; //show information regarding the request echo ' '; print_r(curl_getinfo($curl_connection)); echo ' '; //close the connection curl_close($curl_connection); |
ASP (classic)
Code Block |
---|
<% '/// Include json converter - http://www.aspjson.com %> <% Const apiUrl = "https://air.winkas.net/api/" Dim apiMethod Dim requestBody Dim apiResponse Dim responseBody Dim responseStatus Dim responseMessage Dim httpService Dim token '/// Get access token apiMethod = "Authentication/Authenticate" Set requestBody = New aspJSON With requestBody.data .Add "UserName", "xxxxx" .Add "UserPassword", "xxxxx" .Add "UserContractCode", "xxxxx" End With Set httpService = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0") httpService.open "POST", apiUrl & apiMethod httpService.setRequestHeader "Content-Type", "application/json; charset=utf-8" httpService.send requestBody.JSONoutput apiResponse = httpService.responseText Set responseBody = New aspJSON responseBody.loadJSON apiResponse responseStatus = responseBody.data("WinKasStatus") responseMessage = responseBody.data("WinKasMessage") If responseStatus <> 0 Then Response.Write " Authentication failed! " Response.Write " " & responseMessage & " " Response.End End If token = responseBody.data("WinKasData").item("CurrentToken") |
...