LabOS Private REST API

Overview

This document describes how to use a Public API token to access the Private API. In general the Private API isn’t documented, but an example is given here of how to access the labware catalog.

A basic understanding of Genie’s API patterns (see Public REST API) is required.

Token Exchange

The Public API token can be exchanged for a short lived (5 minute) Private API token.
  • Extract the API {hostname} from the Public API {url}
  • POST the {"jwt": "{token}"} JSON (replacing {token} with your Public API Token) to {hostname}/authn/login
  • The returned jwt attribute contains the short lived Private API Token

Catalog API

Use the Private API token to query the catalog service:
  • Extract the API {hostname} from the Public API {url}
  • GET {hostname}/catalog/library, sending the Private API token in the Authorization header.
  • The returned data attribute contains Genie’s labware catalog.

Python Example

Simple Python application to extract Genie’s labware catalog and store it in a local file.

				
					from json import dumps
from sys import argv, exit as sys_exit
from requests import get, post
 
 
def get_private_api_token(uri: str, token: str) -> str:
    """ Exchanges the API token for a short lived UI token """
    url = f'{uri}/authn/login'
    res = post(url, json={'jwt': token})
    if res.status_code != 200:
        raise ValueError(f'Failed to exchange the API token, error {res.status_code}')
    return res.json()['jwt']
 
 
def get_catalog(uri: str, token: str) -> str:
    """ Retrieves and returns the entirety of the labware catalog """
    url = f'{uri}/catalog/library'
    res = get(url, headers={'Authorization': f'Bearer {token}'})
    if res.status_code != 200:
        raise ValueError(f'GET {url} failed with {res.status_code}')
    return res.json()['data']
 
 
def main() -> None:
    if len(argv) < 3:
        print(f'{argv[0]} url token_file')
        sys_exit(-1)
 
    uri = argv[1]
    with open(argv[2], encoding='utf8') as token_file:
        token = get_private_api_token(uri, token_file.read())
 
    print(dumps(get_catalog(uri, token), indent=4))
 
 
if __name__ == "__main__":
    main()
				
			

Book a Demo

Genie is now in limited Beta. Complete the form below and one of our sales representitives will reach out to you within 24 hours to setup an in-person demo of our platform.