This section is useful for users that want to establish a communication between the portal and other platforms such as billing systems or data analysis for predictive behavior.
It’s also useful for developing mobile apps that interact with the portal without the need to connect directly to the single devices.
This document describes the API exposed by Nethix servers. It’s based on the exchange of XML documents over HTTP following, as much as possible, the REST principles.
The API exposes the following types of resources:
The main purpose of the API is to make possible the creation, modification and deletion of such resources. In general these operation are mapped to HTTP methods.
The API is based on resources. Each resource is reachable through an URL and, depending on the HTTP method used, the server will accomplishes the desired request. The HTTP methods supported by the API are:
The last two methods are implemented for all the resources and they are not specified in the following chapters.
The server will respond to every request received with an HTTP that contains one of the following HTTP status codes:
Status code | Description |
---|---|
200 OK | The request to create a new resource has been satisfied. |
201 Created | The request to create a new resource has been satisfied. |
400 Bad request | The request doesn’t meet this specification. |
401 Unauthorized | The client hasn’t sufficient privileges. |
404 Not found | The resource doesn’t exists. |
405 Not Allowed | The HTTP method used is not supported for requested resource. |
409 Conflict | The request is in conflict with the current resources. For example, if a resource is created twice, the second time it will give this conflict error. |
500 Internal Server Error | An error occurred in the server side. |
All requests require the client to have some privileges.
The API supports two methods to specify clients identity:
In particular the API key can be inserted in the query string using api_key as name, or with the following snippet of XML code:
<ntx>
<authentication>
<api_key>1234</api_key>
</authentication>
</ntx>
Note that HTTP GET method doesn’t allow the attachment of documents in the request, so in this case the API key in the query string must be provided.
An API key is a token that is used to identify a client. This resource must always be called before calling any another resource, otherwise the client won’t be authorized to access the desired resource.
During a session, the first call to this resource needs to send the client’s login and password. The response, if the credentials were correct, will be the API key that will be used for the subsequent calls.
For security reasons, each session will have different API keys.
URL
/api/v1/api_key
GET
Parameters
If a valid API key in not provided or HTTP Basic Auth is not used, the following parameters must be provided:
Response
<ntx>
<authentication>
<api_key>6sBtnYrMhgEehQuY1LA6TRYVArj3YfRI</api_key>
</authentication>
</ntx>
Represents the customer of the client making the request.
URL
/api/v1/customer
GET
Response
<ntx>
<customer>
<name>Nethix S.r.l.</name>
<domains>
<domain>
<id>1</id>
<name>Water control station</name>
</domain>
<domain>
<id>2</id>
<name>Radio station</name>
</domain>
</domains>
</customer>
</ntx>
Represent a collection of devices.
URL
/api/v1/domain(/(id;)*)?
If no domain ids are specified the URL will address all the domains.
GET
Response
<ntx>
<domains>
<domain>
<id>1</id>
<name>Water control station</name>
<vpn_enable>1</vpn_enable>
<devices>
<device>
<id>4</id>
<name>Water tank 1</name>
</device>
<device>
<id>5</id>
<name>Water tank 2</name>
</device>
</devices>
</domain>
</domains>
</ntx>
XML Tags
A physical Nethix device (i.e. WE500).
URL
/api/v1/device(/(id;)*)?
If no device ids are not specified the URL will address all the devices.
GET
Response
<ntx>
<devices>
<device>
<id>4</id>
<name>Water tank 1</name>
<type>1</type>
<last_ip>201713153</last_ip>
<domain>
<id>1</id>
</domain>
<data_delivery_enable>1</data_delivery_enable>
<remote_access_enable>1</remote_access_enable>
<serial_number>0ac59f00000097</serial_number>
<latitude> 45.682608988</latitude>
<longitude> 4.7153341770</longitude>
<variables>
<variable>
<id>3</id>
<name>Water_level</name>
</variable>
<variable>
<id>4</id>
<name>Water_temperture</name>
</variable>
<variable>
<id>5</id>
<name>Filling_pump</name>
</variable>
</variables>
</device>
</devices>
</ntx>
XML Tags
A device variable that was sent to the server at least one time.
URL
/api/v1/variable(/(variable_id;)*)?
If no device id are specified the URL will address all the variables.
GET
Response
<ntx>
<variables>
<variable>
<id>3</id>
<name>Water_level</name>
<access_mode>0</access_mode>
<protocol>0</protocol>
<active_label/>
<inactive_label/>
<size>0</size>
<device>
<id>4</id>
</device>
</variable>
</variables>
</ntx>
XML Tags
A portal log is simple a set of variables and their values at a specific point in time.
URL
/api/v1/device/device_id/portal_log(/(variable_id;)*)?
If no variable ids are specified the URL will address all the portal logs of the device with id equal to device_id.
GET
Parameters
This method accepts the following parameters in order to refine the results:
Response
<ntx>
<portal_logs>
<variables>
<timezone_shift>120</timezone_shift>
<timestamp>1401253621</timestamp>
<variable>
<id>3</id>
<name>Water_level</name>
<value>30</value>
</variable>
<variable>
<id>4</id>
<name>Water_temperture</name>
<value>20</value>
</variable>
</variables>
<variables>
<timezone_shift>120</timezone_shift>
<timestamp>1401253681</timestamp>
<variable>
<id>3</id>
<name>Water_level</name>
<value>29</value>
</variable>
<variable>
<id>4</id>
<name>Water_temperture</name>
<value>20</value>
</variable>
</variables>
</portal_logs>
</ntx>
Request VPN status/data for connecting to the VPN.
This resource is used by the WE500 for getting the necessary data to establish a VPN connection to the Portal. It is useful for the customers that need the WE500 to establish a VPN connection to a server that is not the Nethix Portal.
GET
Response
<ntx>
<vpn>
<reconnection_time>10</reconnection_time>
<status>2</status>
<package_info>
<auth_type>0</auth_type>
<md5_ca_cert>422d6be13d96ebbe44a710eca79bbbff</md5_ca_cert>
<md5_client_conf>d41d8cd98f00b204e9800998ecf8427e</md5_client_conf>
<md5_ta_key>6d05e5f3bab43672a6189c3e1cf05d17</md5_ta_key>
<md5_credentials>05t5f69ca672a6189c3e1cf05dab5</md5_credentials>
</package_info>
</vpn>
</ntx>
<ntx>
<vpn>
<status>2</status>
</vpn>
</ntx>
XML Tags
recconnection_time - when the VPN is not enabled, the client should wait this time (in seconds) before querying the VPN status again.
When the status is disable, the response does not have the package_info tag.
md5_ca_cert - The MD5 of ca.crt
md5_client_conf - The MD5 of client.ovpn
md5_ta_key - The MD5 of ta.key
md5_credentials - The MD5 of credentials.txt
The previous files are transmitted in a single compressed file and checked against these checksums.
More information on how the WE500 uses a VPN can be found in the WE500 VPN section.
Download the VPN files needed for establishing a VPN connection.
This resource is used only after the WE500 received an Update client configuration status reply in the previous resource 3.7. VPN. It is useful if the WE500 needs to establish a VPN connection to a server that is not the Nethix Portal.
GET
Response
Return the VPN files that are grouped in a single archive (tar).
packet
├── ca.crt
├── client.ovpn
├── credentials.txt
└── ta.key
dev tun0
ns-cert-type server
proto tcp
script-security 2
client
topology subnet
remote 212.227.98.217 1194
nobind
tls-exit
ping-restart 120
comp-lzo
verb 3
ca /etc/openvpn/ca.crt
tls-auth /etc/openvpn/ta.key 1
route-up "/sbin/route add -net 10.0.0.0 netmask 255.255.255.0 dev tun0"
auth-user-pass /etc/openvpn/credentials.txt
we500_53cb3e08006d_150890cH7k7c9bABbaldfVFBasUXDtQ5eG
9650f42c851c6de552a646e31lPc6Y1oOfegI5CgXPqSMrnNHO2uY
More information on how the WE500 uses a VPN can be found in the WE500 VPN section.