NAV
shell javascript go python ruby

Introduction

Welcome to the Alliance Machine API! You can use this API to get details on machines and securely send commands to them.

Please reach out to Alliance if you have any questions or concerns.

Authentication

To authorize, use this code:

require "uri"
require "json"
require "net/http"

url = URI("https://api.alliancelslabs.com/ext/login")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["x-api-key"] = "[your_api_key]"
request.body = JSON.dump({
  "email": "useremail@email.com",
  "password": "userpassword"
})

response = https.request(request)
puts response.read_body
import http.client
import json

conn = http.client.HTTPSConnection("api.alliancelslabs.com")
payload = json.dumps({
  "email": "useremail@email.com",
  "password": "userpassword"
})
headers = {
  'Content-Type': 'application/json',
  'x-api-key': '[your_api_key]'
}
conn.request("POST", "/ext/login", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
curl --location --request POST 'https://api.alliancelslabs.com/ext/login' \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: [your_api_key]' \
  --data-raw '{
    "email": "useremail@email.com",
    "password": "userpassword"
  }'
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("x-api-key", "[your_api_key]");

var raw = JSON.stringify({
  email: "useremail@email.com",
  password: "userpassword",
});

var requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: raw,
  redirect: "follow",
};

fetch("https://api.alliancelslabs.com/ext/login", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.log("error", error));
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.alliancelslabs.com/ext/login"
  method := "POST"

  payload := strings.NewReader(`{
    "email": "useremail@email.com",
    "password": "userpassword"
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("x-api-key", "[your_api_key]")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}

Make sure to replace [your_api_key] with your API key.

This API used a combination of an API key and an access token for authorization.

The access token is returned from the login request described below. Only users given programmatic access privileges via Insights will be able login.

This API expects for the API key to be included in all API requests to the server in a header that looks like the following:

x-api-key: [your_api_key]

This API expects the access token to be included in all authenticated requests to the server in a header that looks like the following:

Authorization: Bearer [your_access_token]

Machines

Remote Vend a machine

require "uri"
require "json"
require "net/http"

url = URI("https://api.alliancelslabs.com/ext/remoteVend")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["x-api-key"] = "[your_api_key]"
request["Authorization"] = "Bearer [your_access_token]"
request.body = JSON.dump({
  "vendAmount": "200",
  "machineId": "12345"
})

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

import http.client
import json

conn = http.client.HTTPSConnection("api.alliancelslabs.com")
payload = json.dumps({
  "vendAmount": "200",
  "machineId": "12345"
})
headers = {
  'Content-Type': 'application/json',
  'x-api-key': '[your_api_key]',
  'Authorization': 'Bearer [your_access_token]'
}
conn.request("POST", "/ext/remoteVend", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
curl --location --request POST 'https://api.alliancelslabs.com/ext/remoteVend' \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: [your_api_key]' \
  --header 'Authorization: Bearer [your_access_token]' \
  --data-raw '{
    "vendAmount": "200",
    "machineId": "12345"
}'
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("x-api-key", "[your_api_key]");
myHeaders.append("Authorization", "Bearer [your_access_token]");

var raw = JSON.stringify({
  vendAmount: "200",
  machineId: "12345",
});

var requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: raw,
  redirect: "follow",
};

fetch("https://api.alliancelslabs.com/ext/remoteVend", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.log("error", error));
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.alliancelslabs.com/ext/remoteVend"
  method := "POST"

  payload := strings.NewReader(`{
    "vendAmount": "200",
    "machineId": "12345"
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("x-api-key", "[your_api_key]")
  req.Header.Add("Authorization", "Bearer [your_access_token]")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}

The above command returns JSON structured like this:

{
  "id": "asfasf-asfasf2-asfasf-515125-asfafg",
  "machineId": "1234",
  "controlId": "24624635722457",
  "roomId": "123",
  "createdAt": "2020-05-06T21:00:00.000Z"
}

This endpoint sends a command to a specific machine that vends it with the requested amount.

HTTP Request

POST https://api.alliancelslabs.com/ext/remoteVend

Body Parameters

Parameter Description
vendAmount The request amount to vend
machineId The request machine to vend