IdealNet-Rest

What?

IdealNet-Rest is an API micro service that responds to REST calls
and translates those REST calls to IdealNet PubSub API calls and
returns the results to the REST caller. IdealNet-Rest is designed to
be a bridge between IdealNet PubSub and REST API consumers.

Why?

IdealNet PubSub uses Faye as its API messaging protocol. Faye is far
from a well known protocol, much less popular. In an effort to make
the APIs exposed over IdealNet PubSub's public API interfaces more
accessible, we have build IdealNet-Rest.

How?

To use IdealNet-Rest you simply make a HTTP POST call to the
endpoing that matches the credentials you were provided,
https://rest.idealss.net for production and https://test.rest.idealss.net
for staging/testing as the root URL and then use the
PubSub channel as the URL path. You can find the correct pubsub channel
to use following the API specific documentation, but it generally follows
the format of /{api}/{group}/{siteId}.

Send a JSON body with your request with the following data

  • token - the token provided to you by Ideal to connect to pubsub
  • signature - your key to the request
    • NOTE: this is not the same as the signature used to connect to
      IdealNet PubSub
  • group - the company group identifier
  • siteId - the location identifier
  • payload - this is the contents of the PubSub message, can be obtained
    from the public documentation for the API you are using

Signature Generation

This example uses the crypto-js library to generate the signature, but you can use
whichever hashing library you are comforable with to generate the signature.

The signature is generated by stringifying the payload and appending the private key,
and then hashing the result with SHA256.

const payload = {
		"message": "site_information",
		"v1": {
			"messageID": "156b1ff9-4b65-48fc-96d8-01911127d399",
			"siteID": 123
		}
	};

const pk = 'this-is-my-private-key';
const rb = JSON.stringify(payload);

const sig = CryptoJS.SHA256(rb+pk).toString();

HTTP Request

POST /vr_store/123/456 HTTP/1.1
Content-Type: application/json
Host: test.rest.idealss.net
Content-Length: 460

{
	"token": "9FFD63FWEEB3CC41D0D2ADFEWWEA59FFC50B5DEFDF57FEWE24738CF36A",
	"signature": "04fbb7bf7b71c79fc8bc99eb46232c8073f84a90bd33d87a29acfc1cd85b95df",
	"group": 123,
	"siteId": 456,
	"payload": {
		"message": "site_information",
		"v1": {
			"currentTimeStamp": "2022-06-29T14:39:56.813Z",
			"messageID": "156b1ff9-4b65-48fc-96d8-01911127d399",
			"returnChannel": "/vr_store/123/1x9tzuby2gl7r8mb25obja2t4n50bys/response",
			"siteID": 456
		}
	}
}

Code Examples

Shell

curl --request POST \
  --url https://test.rest.idealss.net/vr_store/123/456 \
  --header 'Content-Type: application/json' \
  --data '{
	"token": "9FFD634625HTJYUTJY0D271DAD12ADFWERHC50B5DEFDF5758939256738CF36A",
	"signature": "04fbb7bf7b71c79fc8bc99eb46232c8073f84a90bd33d87a29acfc1cd85b95df",
	"group": 123,
	"siteId": 456,
	"payload": {
		"message": "site_information",
		"v1": {
			"currentTimeStamp": "2022-06-29T14:39:56.813Z",
			"messageID": "156b1ff9-4b65-48fc-96d8-01911127d399",
			"returnChannel": "/vr_store/123/1x9tzuby2gl7r8mb25obja2t4n50bys/response",
			"siteID": 456
		}
	}
}'

Powershell

$headers=@{}
$headers.Add("Content-Type", "application/json")
$response = Invoke-WebRequest -Uri 'https://test.rest.idealss.net/vr_store/123/456' -Method POST -Headers $headers -ContentType 'application/json' -Body '{
	"token": "9FFD63FWEEB3CC41D0D2ADFEWWEA59FFC50B5DEFDF57FEWE24738CF36A",
	"signature": "04fbb7bf7b71c79fc8bc99eb46232c8073f84a90bd33d87a29acfc1cd85b95df",
	"group": 123,
	"siteId": 456,
	"payload": {
		"message": "site_information",
		"v1": {
			"currentTimeStamp": "2022-06-29T14:39:56.813Z",
			"messageID": "156b1ff9-4b65-48fc-96d8-01911127d399",
			"returnChannel": "/vr_store/123/1x9tzuby2gl7r8mb25obja2t4n50bys/response",
			"siteID": 456
		}
	}
}'

Javascript

const data = JSON.stringify({
  "token": "9FFD63FWEEB3CC41D0D2ADFEWWEA59FFC50B5DEFDF57FEWE24738CF36A",
  "signature": "04fbb7bf7b71c79fc8bc99eb46232c8073f84a90bd33d87a29acfc1cd85b95df",
  "group": 123,
  "siteId": 456,
  "payload": {
    "message": "site_information",
    "v1": {
      "currentTimeStamp": "2022-06-29T14:39:56.813Z",
      "messageID": "156b1ff9-4b65-48fc-96d8-01911127d399",
      "returnChannel": "/vr_store/123/1x9tzuby2gl7r8mb25obja2t4n50bys/response",
      "siteID": 456
    }
  }
});

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;

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

xhr.open("POST", "https://test.rest.idealss.net/vr_store/123/456");
xhr.setRequestHeader("Content-Type", "application/json");

xhr.send(data);

C#

var client = new RestClient("https://test.rest.idealss.net/vr_store/123/456");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n\t\"token\": \"9FFD63FWEEB3CC41D0D2ADFEWWEA59FFC50B5DEFDF57FEWE24738CF36A\",\n\t\"signature\": \"04fbb7bf7b71c79fc8bc99eb46232c8073f84a90bd33d87a29acfc1cd85b95df\",\n\t\"group\": 123,\n\t\"siteId\": 456,\n\t\"payload\": {\n\t\t\"message\": \"site_information\",\n\t\t\"v1\": {\n\t\t\t\"currentTimeStamp\": \"2022-06-29T14:39:56.813Z\",\n\t\t\t\"messageID\": \"156b1ff9-4b65-48fc-96d8-01911127d399\",\n\t\t\t\"returnChannel\": \"/vr_store/123/1x9tzuby2gl7r8mb25obja2t4n50bys/response\",\n\t\t\t\"siteID\": 456\n\t\t}\n\t}\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Java

HttpResponse<String> response = Unirest.post("https://test.rest.idealss.net/vr_store/123/456")
  .header("Content-Type", "application/json")
  .body("{\n\t\"token\": \"9FFD63FWEEB3CC41D0D2ADFEWWEA59FFC50B5DEFDF57FEWE24738CF36A\",\n\t\"signature\": \"04fbb7bf7b71c79fc8bc99eb46232c8073f84a90bd33d87a29acfc1cd85b95df\",\n\t\"group\": 123,\n\t\"siteId\": 456,\n\t\"payload\": {\n\t\t\"message\": \"site_information\",\n\t\t\"v1\": {\n\t\t\t\"currentTimeStamp\": \"2022-06-29T14:39:56.813Z\",\n\t\t\t\"messageID\": \"156b1ff9-4b65-48fc-96d8-01911127d399\",\n\t\t\t\"returnChannel\": \"/vr_store/123/1x9tzuby2gl7r8mb25obja2t4n50bys/response\",\n\t\t\t\"siteID\": 456\n\t\t}\n\t}\n}")
  .asString();

Python

import http.client

conn = http.client.HTTPSConnection("test.rest.idealss.net")

payload = "{\n\t\"token\": \"9FFD63FWEEB3CC41D0D2ADFEWWEA59FFC50B5DEFDF57FEWE24738CF36A\",\n\t\"signature\": \"04fbb7bf7b71c79fc8bc99eb46232c8073f84a90bd33d87a29acfc1cd85b95df\",\n\t\"group\": 123,\n\t\"siteId\": 456,\n\t\"payload\": {\n\t\t\"message\": \"site_information\",\n\t\t\"v1\": {\n\t\t\t\"currentTimeStamp\": \"2022-06-29T14:39:56.813Z\",\n\t\t\t\"messageID\": \"156b1ff9-4b65-48fc-96d8-01911127d399\",\n\t\t\t\"returnChannel\": \"/vr_store/123/1x9tzuby2gl7r8mb25obja2t4n50bys/response\",\n\t\t\t\"siteID\": 456\n\t\t}\n\t}\n}"

headers = { 'Content-Type': "application/json" }

conn.request("POST", "/vr_store/123/456", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

Ruby

require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://test.rest.idealss.net/vr_store/123/456")

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["Content-Type"] = 'application/json'
request.body = "{\n\t\"token\": \"9FFD63FWEEB3CC41D0D2ADFEWWEA59FFC50B5DEFDF57FEWE24738CF36A\",\n\t\"signature\": \"04fbb7bf7b71c79fc8bc99eb46232c8073f84a90bd33d87a29acfc1cd85b95df\",\n\t\"group\": 123,\n\t\"siteId\": 456,\n\t\"payload\": {\n\t\t\"message\": \"site_information\",\n\t\t\"v1\": {\n\t\t\t\"currentTimeStamp\": \"2022-06-29T14:39:56.813Z\",\n\t\t\t\"messageID\": \"156b1ff9-4b65-48fc-96d8-01911127d399\",\n\t\t\t\"returnChannel\": \"/vr_store/123/1x9tzuby2gl7r8mb25obja2t4n50bys/response\",\n\t\t\t\"siteID\": 456\n\t\t}\n\t}\n}"

response = http.request(request)
puts response.read_body

DevOps Stuff

Documentation

Test Coverage