clock for blog

Office Hours
Mon-Fri 09:00-21:00

Knowledgebase: Skinning and API
Web API
Posted by Panagiotis Mantzouranis on 22 February 2013 05:28 PM

Gizmo's WEB API Is a REST API implementation. Basic goal is to allow Gizmo functionality to be extended and provide means for Server and Client control, monitoring etc.

Getting started

First action required is to enable the WEB API in server settings.
WEB API can be enabled in server settings menu under general options.
A valid port must be specified (default 8080).


Note: Make sure no other application or service on Gizmo Server pc is using chosen port , otherwise WEB API will fail to start.

 

Documentation

You can get a list of supported commands and theirs documentation by navigating to the root/index page with your web browser. Depending on the WEB API port specified in settings the WEB API documentation can be accessed by navigating to URL

 http://<Server IP or Host Name>:< WEB API Port>

Note: If WEB API port is set to 80 then you don’t need to specify port in the WEB API address URL.

 

 

Authentication

The current authentication scheme used by Gizmo is HTTP Basic.
Valid operator credentials must be specified with each and every call to the WEB API.

Calling & Testing WEB API

You can call and execute WEB API commands either from your WEB Browser or with most REST Clients such as http://restclient.net/

PHP Example

Purpose: List connected or registered hosts.

<?php

 

// Set request function, username and password

$func         = 'Hosts/Get?';

$curl         = 'http://<WEB API IP OR HOSTNAME>:<WEB API PORT>/' . $func;

$user         = '<USERNAME>';

$pass         = '<PASSWORD>';

 

// Get data

$ch                  = curl_init( $curl );

$options      = array(

                           CURLOPT_RETURNTRANSFER     => true,

                           CURLOPT_USERPWD                   => $user . ":" . $pass,

                           CURLOPT_HTTPHEADER         => array('Content-type: application/json')

                     );

curl_setopt_array( $ch, $options );

 

$res          = curl_exec( $ch );

$inf                 = curl_getinfo( $ch );

$err          = curl_errno( $ch );                                  

 

curl_close( $ch );

 

// Check response

$inf['http_code'] != 200 ?exit( 'Error: ' . $inf['http_code'] ) : print_r("<strong>Success executing API Command</strong><br>");

 

// Parse data

$data = json_decode( $res, true );

echo '<pre>';

print_r( $data );

 

Getting Help

You can ask question regarding WEB API in our dedicated forum section: http://forum.gizmopowered.net/viewforum.php?f=26

or through our official support system: http://support.gizmopowered.net

(9 vote(s))
Helpful
Not helpful