These docs are for v3.0.2. Click to read the latest docs for v5.

Send Binary Using REST

BASE_URL = http(s)://your_host_or_ip/api

HTTP File Upload

  • Endpoint: ${BASE_URL}/push/bin/file/{dkey}/{akey}/{did}/{dmdl}/{fwver}/{type }
    • type is the binary rule name
  • Content-Type: multipart/form-data
  • Method: POST
  • File Form Parameter: binfile
curl --request POST \
  --url https://your_host_or_ip/api/push/bin/file/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule \
  --header 'accept: application/json' \
  --header 'content-type: multipart/form-data' \
  --data '{"binfile":"data:application/json;name=message.json;base64,eyJsYXRpdHVkZSI6MzIuNzc5MTY3LCJsb25naXR1ZGUiOi05Ni44MDg4OTEsInRlbXBlcmF0dXJlIjoyNiwiaHVtaWRpdHkiOjc3LCJwcmVjaXBpdGF0aW9uIjowLCJ3aW5kIjoxMX0K"}'
var request = require("request");

var options = {
  method: 'POST',
  url: 'https://your_host_or_ip/api/push/bin/file/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule',
  headers: {accept: 'application/json', 'content-type': 'multipart/form-data'},
  body: '{"binfile":"data:application/json;name=message.json;base64,eyJsYXRpdHVkZSI6MzIuNzc5MTY3LCJsb25naXR1ZGUiOi05Ni44MDg4OTEsInRlbXBlcmF0dXJlIjoyNiwiaHVtaWRpdHkiOjc3LCJwcmVjaXBpdGF0aW9uIjowLCJ3aW5kIjoxMX0K"}'
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://your_host_or_ip/api/push/bin/file/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'multipart/form-data'
request.body = "{\"binfile\":\"data:application/json;name=message.json;base64,eyJsYXRpdHVkZSI6MzIuNzc5MTY3LCJsb25naXR1ZGUiOi05Ni44MDg4OTEsInRlbXBlcmF0dXJlIjoyNiwiaHVtaWRpdHkiOjc3LCJwcmVjaXBpdGF0aW9uIjowLCJ3aW5kIjoxMX0K\"}"

response = http.request(request)
puts response.read_body
var data = "{\"binfile\":\"data:application/json;name=message.json;base64,eyJsYXRpdHVkZSI6MzIuNzc5MTY3LCJsb25naXR1ZGUiOi05Ni44MDg4OTEsInRlbXBlcmF0dXJlIjoyNiwiaHVtaWRpdHkiOjc3LCJwcmVjaXBpdGF0aW9uIjowLCJ3aW5kIjoxMX0K\"}";

var xhr = new XMLHttpRequest();

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://your_host_or_ip/api/push/bin/file/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule");
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("content-type", "multipart/form-data");

xhr.send(data);
import requests

url = "https://your_host_or_ip/api/push/bin/file/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule"

payload = "{\"binfile\":\"data:application/json;name=message.json;base64,eyJsYXRpdHVkZSI6MzIuNzc5MTY3LCJsb25naXR1ZGUiOi05Ni44MDg4OTEsInRlbXBlcmF0dXJlIjoyNiwiaHVtaWRpdHkiOjc3LCJwcmVjaXBpdGF0aW9uIjowLCJ3aW5kIjoxMX0K\"}"
headers = {
    'accept': "application/json",
    'content-type': "multipart/form-data"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

HTTP Encoded Data Posting

  • Endpoint: ${BASE_URL}/push/bin/data/{dkey}/{akey}/{did}/{dmdl}/{fwver}/{type }
    • type is the binary rule name
  • Query Parameters
    • format
      • Allowed values (TEXT | HEX | BASE64)
        • If you want to upload a byte array, use one of HEX or BASE64 encoding
    • contentType
      • Standard file content types like below
      • image/jpg
      • text/plain
      • application/octet-stream
  • Content-Type: text/plain
  • Method: POST
  • Body: Your data as plain string or encoded HEX or BASE64 binary data
curl --request POST \
  --url 'https://your_host_or_ip/api/push/bin/data/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule?format=BASE64&contentType=application%2Fjson' \
  --header 'accept: application/json' \
  --header 'content-type: text/plain' \
  --data '"ew0KICAibGF0aXR1ZGUiOiAzMi43NzkxNjcsDQogICJsb25naXR1ZGUiOiAtOTYuODA4ODkxLA0KICAidGVtcGVyYXR1cmUiOiAyNiwNCiAgImh1bWlkaXR5IjogNzcsDQogICJwcmVjaXBpdGF0aW9uIjogMCwNCiAgIndpbmQiOiAxMQ0KfQ=="'
var request = require("request");

var options = {
  method: 'POST',
  url: 'https://your_host_or_ip/api/push/bin/data/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule',
  qs: {format: 'BASE64', contentType: 'application/json'},
  headers: {accept: 'application/json', 'content-type': 'text/plain'},
  body: '"ew0KICAibGF0aXR1ZGUiOiAzMi43NzkxNjcsDQogICJsb25naXR1ZGUiOiAtOTYuODA4ODkxLA0KICAidGVtcGVyYXR1cmUiOiAyNiwNCiAgImh1bWlkaXR5IjogNzcsDQogICJwcmVjaXBpdGF0aW9uIjogMCwNCiAgIndpbmQiOiAxMQ0KfQ=="'
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://your_host_or_ip/api/push/bin/data/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule?format=BASE64&contentType=application%2Fjson")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'text/plain'
request.body = "\"ew0KICAibGF0aXR1ZGUiOiAzMi43NzkxNjcsDQogICJsb25naXR1ZGUiOiAtOTYuODA4ODkxLA0KICAidGVtcGVyYXR1cmUiOiAyNiwNCiAgImh1bWlkaXR5IjogNzcsDQogICJwcmVjaXBpdGF0aW9uIjogMCwNCiAgIndpbmQiOiAxMQ0KfQ==\""

response = http.request(request)
puts response.read_body
var data = "\"ew0KICAibGF0aXR1ZGUiOiAzMi43NzkxNjcsDQogICJsb25naXR1ZGUiOiAtOTYuODA4ODkxLA0KICAidGVtcGVyYXR1cmUiOiAyNiwNCiAgImh1bWlkaXR5IjogNzcsDQogICJwcmVjaXBpdGF0aW9uIjogMCwNCiAgIndpbmQiOiAxMQ0KfQ==\"";

var xhr = new XMLHttpRequest();

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://your_host_or_ip/api/push/bin/data/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule?format=BASE64&contentType=application%2Fjson");
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("content-type", "text/plain");

xhr.send(data);
import requests

url = "https://your_host_or_ip/api/push/bin/data/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule"

querystring = {"format":"BASE64","contentType":"application/json"}

payload = "\"ew0KICAibGF0aXR1ZGUiOiAzMi43NzkxNjcsDQogICJsb25naXR1ZGUiOiAtOTYuODA4ODkxLA0KICAidGVtcGVyYXR1cmUiOiAyNiwNCiAgImh1bWlkaXR5IjogNzcsDQogICJwcmVjaXBpdGF0aW9uIjogMCwNCiAgIndpbmQiOiAxMQ0KfQ==\""
headers = {
    'accept': "application/json",
    'content-type': "text/plain"
    }

response = requests.request("POST", url, data=payload, headers=headers, params=querystring)

print(response.text)

HTTP Complex JSON Posting

  • This is just a convenient API to push a complex JSON object, you could use the file upload API to achieve the same result
  • Endpoint: ${BASE_URL}/push/bin/json/{dkey}/{akey}/{did}/{dmdl}/{fwver}/{type }
    • type is the binary rule name
  • Content-Type: application/json
  • Method: POST
  • Body: Your JOSN Object
curl --request POST \
  --url 'https://your_host_or_ip/api/push/bin/json/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule' \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"latitude":32.779167,"longitude":-96.808891,"temperature":26,"humidity":77,"precipitation":0,"wind":11}'
var request = require("request");

var options = {
  method: 'POST',
  url: 'https://your_host_or_ip/api/push/bin/json/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule',
  headers: {accept: 'application/json', 'content-type': 'application/json'},
  body: '{"latitude":32.779167,"longitude":-96.808891,"temperature":26,"humidity":77,"precipitation":0,"wind":11}'
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://your_host_or_ip/api/push/bin/json/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'application/json'
request.body = "{"latitude":32.779167,"longitude":-96.808891,"temperature":26,"humidity":77,"precipitation":0,"wind":11}"

response = http.request(request)
puts response.read_body
var data = "{"latitude":32.779167,"longitude":-96.808891,"temperature":26,"humidity":77,"precipitation":0,"wind":11}";

var xhr = new XMLHttpRequest();

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://your_host_or_ip/api/push/bin/json/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule");
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("content-type", "application/json");

xhr.send(data);
import requests

url = "https://your_host_or_ip/api/push/bin/json/your_domain_key/your_api_key/your_device_id/device_model/fw_version/your_binary_rule"

payload = "{"latitude":32.779167,"longitude":-96.808891,"temperature":26,"humidity":77,"precipitation":0,"wind":11}"
headers = {
    'accept': "application/json",
    'content-type': "application/json"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)