API

IOT API

The Internet of Things API (IOTA) provides a simple REST endpoint for metrics, compatible with any hardware that can make web requests e.g. Arduino, Raspberry PI, ESP32, etc

Use the following persponalized endpoint to send data to the IOT API:

https://usermetrics.net/api/store/xxxxx-appkey-xxxxx/tag/value
Rate Limit
Free 100 requests per hour
Pro 1000+ requests per hour

Javascript Example

/**
 * Javascript Example
 */

/* Javascript Example */
fetch(`https://usermetrics.net/api/store/xxxxx-appkey-xxxxx/hello/30416.1`);

/* Older Javascript Example */
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://usermetrics.net/api/store/xxxxx-appkey-xxxxx/mytag/myvalue", true);
xhr.send();
                    

C++ Example

/** C++ Example */
#include 
#include 

int main() {
    CURL *curl;
    CURLcode res;

    curl_global_init(CURL_GLOBAL_DEFAULT);
    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "https://usermetrics.net/api/store/xxxxx-appkey-xxxxx/mytag/myvalue");
        res = curl_easy_perform(curl);
        if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
        curl_easy_cleanup(curl);
    }
    curl_global_cleanup();
    return 0;
}

Arduino Example

/** Arduino Example */
#include 
#include 

char serverAddress[] = "usermetrics.net";
int port = 443;
WiFiSSLClient wifiClient;
HttpClient client = HttpClient(wifiClient, serverAddress, port);

void setup() {
    Serial.begin(9600);
    while (!Serial);
    Serial.println("Starting Arduino...");

    // Connect to WiFi
    WiFi.begin("SSID", "password");
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("Connected to WiFi!");
}

void loop() {
    Serial.println("Making a request to UserMetrics...");
    client.get("/api/store/xxxxx-appkey-xxxxx/mytag/myvalue");
    int statusCode = client.responseStatusCode();
    String response = client.responseBody();
    Serial.print("Status code: ");
    Serial.println(statusCode);
    Serial.print("Response: ");
    Serial.println(response);
    delay(5000);
}

Python Example

/** Python Example */
import requests

url = "https://usermetrics.net/api/store/xxxxx-appkey-xxxxx/mytag/myvalue"
response = requests.get(url)
print(response.status_code)
print(response.text)
                    

Node.js Example

Try the npm @usermetrics/usermetrics package for more features


const https = require('https');

https.get('https://usermetrics.net/api/store/xxxxx-appkey-xxxxx/mytag/myvalue', (resp) => {
    let data = '';

    resp.on('data', (chunk) => {
        data += chunk;
    });

    resp.on('end', () => {
        console.log(data);
    });

}).on("error", (err) => {
    console.log("Error: " + err.message);
});
                    

Rust Example


/** Rust Example */
use std::io::Read;
use reqwest;

fn main() {
    let mut response = reqwest::get("https://usermetrics.net/api/store/xxxxx-appkey-xxxxx/mytag/myvalue").unwrap();
    let mut content = String::new();
    response.read_to_string(&mut content).unwrap();
    println!("{}", content);
}