API Authorization

API Authorization

WinKAS Api is tokens based and you will need to provide an active token to all API calls. To get a token, you will need to call the “Authorization” API and it requires the following information:

  • ContractId (Normal customer’s license or agreementId)

  • Username (The username that the customer has created with API access)

  • Password: (The assigned password for the username)

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

Requesttype: Post

Body: {“UserName”:”NAME”, “UserPassword”:”PASSWORD”, “UserContractCode”:”CODE”}

Parameters description:

All parameters are string

Response example:

{     "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#

using System; using System.Net.Http; using System.Net.Http.Json; // Kræver System.Net.Http.Json (fra .NET 5+ eller NuGet) using System.Threading.Tasks; using Newtonsoft.Json; // Bevaret til dynamic parsing som i dit eksempel public async Task<string> GetTokenAsync() { // Brug helst en genbrugt HttpClient instans i stedet for 'using' her using (var client = new HttpClient()) { var authData = new { UserName = "xxxxx", UserPassword = "xxxxx", UserContractCode = "xxxxx" }; // Sender POST som JSON var response = await client.PostAsJsonAsync("https://air.winkas.net/api/Authentication/Authenticate", authData); // Sikrer at kaldet lykkedes (kaster exception ved fejl-statuskoder) response.EnsureSuccessStatusCode(); // Læser svar som string string jsonAuth = await response.Content.ReadAsStringAsync(); // Parser dynamic indhold ligesom i din oprindelige kode dynamic jsonContent = JsonConvert.DeserializeObject(jsonAuth); string token = jsonContent.WinKasData.CurrentToken; return token; } }

Javascript

$(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

//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)

<% '/// 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")