RESTful API Introduction

INTRODUCTION

Western Telematic offers a growing set of RESTful API calls allowing you to access some of the common core functionalities in the full line of WTI products.

  • The WTI RESTful APIs can be accessed via the web end point of all current WTI units.
  • The WTI RESTful APIs can be used with any language or utility that can utilize an http/https call.

Although https is not required it is highly recommended, otherwise the BASIC authentication usernames and passwords could be intercepted by third parties while being transmitted in cleartext via http.


To see the latest WTI RESTful API documentation please go here:
https://ftp.wti.com/pub/TechSupport/Restful_WTI/current/api/api.html

Or if you need a RAML file to use with your development system, you can download it here: https://ftp.wti.com/pub/TechSupport/Restful_WTI/current/api/api.raml

AUTHENTICATION

For every request you make, you must provide a username and password. All WTI units utilize BASIC authentication. Refer to your tool or language documentation you are using to implement this type of credential authentication.

RESPONSE FORMAT

The default API response is JSON

TESTING THE RESTful API

To test the API, WTI has provided samples for the command line WGET and Python. Always start out with a simple GET call such as the temperature or version query. This will make sure that your basic mechanisms are working.

WGET EXAMPLE

Testing with the command line utility WGET we start off with a simple GET command to retrieve the temperature of the WTI unit.

wget http://192.168.0.158/api/v2/status/temperature --user=super --password=super

which will return the following JSON block:

 {

 "status": {"code": "0","text": "OK"},

 "temperature": "74",

 "format": "F",

 "timestamp": "2018-02-01T18:15:44+00:00"

 }

Some WTI RESTful calls require POST type of data, which is in the form of a JSON block. For example, to boot plug 1 on a WTI power unit, you can use the following WGET command to perform the booting of plug 1.

wget http://192.168.0.158/api/v2/config/powerplug --user=super --password=super --post-data='{"plug": 1, "state": "boot"}'

For the WGET post-data, please note the use of single quotes vs. the use of double quotes. This will return the following JSON block:

{
"status": {"code": "0","text": "ok"}, 
"powerplugs": [ 
{ "plug": "1", "plugname": "Outlet_A1", "state": "off", "busy": "1", "bootdelay": "0.5 Secs", "priority": "1", "plugoffreason": "0" } 
] 
}

Python EXAMPLE

To test WTI RESTful  calls in Python, you can access a growing library of examples over at WTI's GitHub repository located at: https://github.com/wtinetworkgear

APPENDIX A

Multiple plug control at in the same call.

WGET EXAMPLE

wget http://192.168.0.158/api/v2/config/powerplug --user=super --password=super --post-data='{"plug":1, "state": "boot"},{"plug":2, "state": "boot"}'

For the WGET post-data, please note the use of single quotes vs. the use of double quotes. This will return the following JSON block:

{ 
"status": {"code": "0","text": "ok"}, 
"powerplugs": [ 
{ "plug": "1", "plugname": "Outlet_A1", "state": "off", "busy": "1", "bootdelay": "0.5 Secs", "priority": "1", "plugoffreason": "0" }, 
{"plug": "2", "plugname": "Outlet_A2", "state": "on", "busy": "1", "bootdelay": "0.5 Secs", "priority": "2", "plugoffreason": "0" } 
] 
}