ezeio2:apiref:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ezeio2:apiref:start [2021-01-27 22:16] andrehezeio2:apiref:start [2022-08-11 17:17] (current) – [Version 1 API] andreh
Line 8: Line 8:
 === Credentials === === Credentials ===
  
-API credentials must be created for the group. The credentials consists of an ID number and a 24 character key.+API credentials must be created for the account. The credentials consists of an ID number and a 24 character key. Please keep the API credentials secret.
  
 All API calls require authentication using Digest Auth (RFC 2617). The API ID number shall be used as the Digest Auth Username, and the API key shall be used as the Password. All API calls require authentication using Digest Auth (RFC 2617). The API ID number shall be used as the Digest Auth Username, and the API key shall be used as the Password.
Line 14: Line 14:
 All API calls require HTTPS using TLS v1.2 or TLS v1.3. Calls via unencrypted HTTP are not allowed. All API calls require HTTPS using TLS v1.2 or TLS v1.3. Calls via unencrypted HTTP are not allowed.
  
-All API calls return the time of the request (reqtime) and a result code in (status). +All API calls return data encoded in JSON. The response include the time of the request (reqtime) and a result code in (status). If the call was successful, the status will be “OK”. If there was an error, status will be a string detailing the error.
- +
-If the call was successful, the status will be “OK”. If there was an error, status will be a string detailing the error. +
  
  
Line 27: Line 24:
 Please note that using the API requires knowledge in programming and standard web technologies. eze System is happy to support with specifics related to the API, but we can't teach programming. Please note that using the API requires knowledge in programming and standard web technologies. eze System is happy to support with specifics related to the API, but we can't teach programming.
 </WRAP> </WRAP>
 +
 +=== Available API functions ===
 +{{indexmenu>ezeio2:apiref}}
 +
 +=== API fair use ===
 +The API functionality is a shared resource, and as such requires 'good behavior' from those that use it. Access to the API features are logged and monitored by eze System, and if we detect inefficient or for any reason concerning usage we will contact the user and/or suspend the IP/access key until the problem is resolved.
 +
 +The API also implements flood control counters to limit excessive calls as follows;
 +  * Per 60 seconds : 100 API calls per key
 +  * Per 24 hours : 50000 API calls per key
 +If these limits are exceeded, an error is returned. The counters are automatically reset at the end of the interval.
 +
 +=== Example code ===
 +This example shows how to call the "syslog" API endpoint using PHP.
 +
 +<code php ezeioAPIexample.php>
 +<?php
 +    define("APIURI", "https://api.eze.io/v1/syslog");
 + 
 +    // API keyID and key needs to be set up in eze.io under Groups->API.
 +    define("APIKeyID", "00000");
 +    define("APIKey", "12345abcde12345abcde12345abcdeff");
 + 
 +    $params = array(
 +        "ABC000",               // ezeio serial
 +        "from=2021-11-01",      // start of data
 +        "to=2021-11-10",        // end of data
 +        "fields=1,12,cRSSI",    // list of fields we care about
 +        "1h",                   // 1h interval data..
 +        "mean"                  // ..as averages
 +    );
 + 
 +    // Set up cURL
 +    $ch = curl_init();
 +    curl_setopt($ch, CURLOPT_URL, APIURI."/".implode("/", $params));
 + 
 +    // All API calls use Digest AUTH
 +    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);        
 +    curl_setopt($ch, CURLOPT_USERPWD, APIKeyID.":".APIKey);
 + 
 +    // Set a 5s timeout, return any received data, ignore ssl errors
 +    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
 +    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
 +    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 + 
 +    // Execute the cURL request
 +    $response = curl_exec($ch);
 +    if(curl_errno($ch))         // if there's an error..
 +        die(curl_error($ch));   // quit and show what the problem is
 +    curl_close($ch);
 + 
 +    // Decode the json reply into an associative array
 +    $json = json_decode( $response, TRUE );                     
 + 
 +    // Show what we received
 +    print_r($json);
 +</code>
 +
 +Below is a minimal example fetching current status using Python
 +
 +<code python ezeioAPIexample.py>
 +import requests
 +from requests.auth import HTTPDigestAuth
 +from pprint import pprint # Just used to format the output
 +
 +# API credentials from eze.io -> Groups Settings -> Manage API Keys
 +apikeyid = '00000'
 +apikey = '12345abcde12345abcde12345abcdeff'
 +
 +# API endpoint and request - see doc.eze.io
 +apiurl = 'https://api.eze.io/v1/status/ABC000'
 +
 +# Send request
 +r = requests.get(apiurl, auth=HTTPDigestAuth(apikeyid, apikey))
 +
 +# Convert response to a dictionary
 +data = r.json()
 +
 +# Dump whole dictionary to screen
 +pprint(data)
 +
 +# Print the value of field 1
 +print(data['fields']['1']['value'])
 +</code>
  • ezeio2/apiref/start.1611785799.txt.gz
  • Last modified: 2021-01-27 22:16
  • by andreh