top of page

KIWIRE DOCUMENTATION

Integration - API

Kiwire has a built in API (Application Protocol Interface) that let your application connect and manipulate system and retrieve data from your own developed application. For optional reading, Technical information on the Kiwire API specification will be included below. To access the API module click on Integrations > API from the navigation. The configuration screen will be displayed. This includes main and permission for Kiwire platform.


The field and its function description is listed below.



API Permission

The API permission tab enables you to configure the API permission given to the connecting application. Use “toggle” to enable the permission of the API interface to 3rd party.


The field and its function description is listed below.



<h3><strong>Supported Modules</strong></h3>

<p>Currently, Kiwire supports API for the following modules :</p>


  • Admin user

  • NAS

  • Devices

  • Profile

  • Login

  • User

  • Voucher

General Result

Every API request send to Kiwire will be respond as a JSON object with the below structure;

  • is_success – boolean (always true)

  • result_msg – string (message generated as a result of a request)

  • ret_data – array (items for get method)

Additionally, Kiwire also will respond with an error message based on the below structure;

  • error – string (error message)

API Login

Every API request needs to perform login to obtain token key which then will be used to make request to module.

URL - http://{{kiwire_ip}}/admin/agent/api_login.php

Parameters Required


Response

{
"status": "success",
"token": "80d588720c2203739ad643d405e63136"
}

Notes

This action will create an API session inside Kiwire which expires after 20 minutes. You have to re-login after 20 minutes to make another API request.

The token provided will be use in all API request.


Module: Login

URL

[POST] http://{{kiwire_ip}}/apiv2/login/{{method}}/{{value}}

Where {{method}} can be:

  • history : List of sessions created for particular account

  • online : Send request to NAS for login user device as per account provided

  • unauthorize : List of user device which are not authorised

Where {{value}} can be:

  • username : For history method

  • nas id : For unauthorize method

Parameters Required

History - List of sessions created for particular account


*If username is not provided in this request, the session list for all user will be returned.

Online - Send request to NAS for login user device as per account provided



*Parameters marked as optional will only be used if user creation required (user not existed). If these values are not provided during the creation process, default value will be used as per below;


Unauthorize - List of user device which are not authorized


Response

{
“is_success” : “true”, // always true to indicate that the request has been processed
“result_message” : “”, // return a string of status for online method
“return_data” : [] // return items found in database for unauthorize and history
}

Module: Administrator User

URL [POST] http://{{kiwire_ip}}/apiv2/admin/{{method}}/{{value}}

Where {{method}} can be:

  • create

  • delete

  • get

Where {{value}} can be: administrator

  • username

Parameters Required

Create

Delete


Get

Notes

For get method, if {{value}} not provided then Kiwire will return all available items subject to start and limit.

Module: User Account

URL

[POST] http://{{kiwire_ip}}/apiv2/user/{{method}}/{{value}}

Where {{method}} can be:

  • create

  • delete

  • get

Where {{value}} can be:

  • user account

Parameters Required

Create

Delete

Get


Notes

For get method, if {{value}} not provided then Kiwire will return all available items subject to start and limit.

Module: NAS

URL

[POST] http://{{kiwire_ip}}/apiv2/nas/{{method}}/{{value}}

Where {{method}} can be:

  • create

  • delete

  • get

Where {{value}} can be:

  • nas identity

Parameters Required

Create


Delete

Get

Notes

For get method, if {{value}} not provided then Kiwire will return all available items subject to start and limit.

Module: Devices

URL

[POST] http://{{kiwire_ip}}/apiv2/device/{{method}}/{{value}}

Where {{method}} can be:

  • create

  • delete

  • get

Where {{value}} can be:

  • voucher code

Parameters Required

Create


Delete

Get

Notes

For get method, if {{value}} not provided then Kiwire will return all available items subject to start and limit.

Module: Profile

URL

[POST] http://{{kiwire_ip}}/apiv2/profile/{{method}}/{{value}}

Where {{method}} can be:

  • create

  • delete

  • get

Where {{value}} can be:

  • profile name

Parameters Required

Create

Delete

Get

Notes

For get method, if {{value}} not provided then Kiwire will return all available items subject to start and limit.

Sample API Code

<?php
session_start();
// Configuration
$cloud_id = "default";
$username = "admin";
$password = "youradminpassword";
$api_key = "Nsf7a86787asvh&5asfkasdfNDJFNKsa=sS"; // API key get from Kiwire
$kiwire_host = "http://kiwireserveraddress.com";
$kiwire_port = 8081;
/* *********************
** -- START --
** LOGIN & TOKEN PART
*/
// If token already exist, check if the token expired or not
if(isset($_SESSION['login_token']) && isset($_SESSION['login_last_time'])){
$time_current = time();
$time_login_expired = strtotime("+20 minutes", $_SESSION['login_last_time']);
if($time_current < $time_login_expired) $do_not_get_token = true;
}
// If token not exist or token expired, get new token
if(empty($do_not_get_token)){
// setup api_login method to get the token
$login_api_data = Array(
"url" => $kiwire_host . "/admin/agent/api_login.php",
"port" => $kiwire_port,
"params" => Array(
"code" => MD5( $username . "|" . $password ),
"cloud_id" => $cloud_id,
),
);
// execute api_login method to get the token
$result_json = sendhttpreq($login_api_data['url'], $login_api_data['params'], "POST", $login_api_data['port']);
$result_array = json_decode($result_json, true);
$_SESSION['login_token'] = $result_array['token']; //the token will expired in 20 minutes and must renew the token each 20 minutes
$_SESSION['login_last_time']= time();
}

/*
** -- END --
** LOGIN & TOKEN PART
** ********************* */
// this $current_datetime variable
// must be included in the hashed API Key ( MD5($real_api_key . $login_token . $current_datetime) )
// also must be included in params as "time"
// - refer the code below
$current_datetime = date("YmdHis");
// set up login history method
// you can refer to documentation for another method
$api_call_data = Array(
"url" => $kiwire_host . "/apiv2/login/history",
"port" => $kiwire_port,
"params" => Array(
"start_time" => "2017-06-08 00:00:00",
"end_time" => "2017-06-08 23:59:59",
"token" => $_SESSION['login_token'],
"api_key" => MD5( $api_key . $_SESSION['login_token'] . $current_datetime ),
"time" => $current_datetime,
"cloud_id" => $cloud_id,
),
);

// execute login history method
$result_json = sendhttpreq($api_call_data['url'], $api_call_data['params'], "POST", $api_call_data['port']);
$result_array = json_decode($result_json, true);

// if login token expired, refresh to get new token
if(substr($result_array['error'], 0, 13) == "login expired"){
session_destroy();
echo "<script>window.location.reload();</script>";
}

// display the result
var_dump($result_array);

// Function for sending HTTP Request
function sendhttpreq($url, $data, $method="GET", $port=80){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_PORT, $port);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
?>

List of Error Message


Comments


Commenting has been turned off.
Related Post
bottom of page