APIs are the backbone of many modern applications. They allow different systems and software to communicate and share data, making it possible for developers to create seamless and integrated user experiences. Without APIs, many of the apps and services we rely on every day would not be possible, from social media platforms to e-commerce websites and more. They are the unsung heroes of software development, working quietly behind the scenes to connect different systems and make them work together in harmony.

Turing Pi 2 BMC is no different. The Web interface and $tpcli are both using the same API in background to interact with various board features. You can even skip these built-in tools and call the API with curl commands or any other external application. In the advance guide section, we will go over how to extend this API with your own functions.

API Endpoints

Any API that wants to be useful requires proper documentation of its endpoints. What to call and to what effect. Mind you, this list should grow as we add more and more functionality.

Endpoint: /api/bmc

Description:
This endpoint allows access to the baseboard management controller (BMC) of a computer system.

Methods:
- POST

Data Type:
- JSON
Query Parameters:
- opt (required): The operation to perform. Valid values are "get" or "set". 
For opt=get:
    - type (required): The type of information to retrieve. 
                       Valid values are "nodeinfo", "power", "usb", "sdcard".
For opt=set:
    To set USB to node:
      - type (required): "usb"
      - mode (required): Valid values are "0" or "1". "0" for Host, "1" for Device
      - node (required): Valid values are "0", "1", "2", "3". Relating to slots Node1-4 
    Example: /api/bmc?opt=set&type=usb&mode=1&node=0

    To set Power to Module1-4:
      - type (required): "power"
      - node[1-4] (required): Valid values are "0" or "1". "0" for OFF, "1" for ON. 
                              You can chain the requests.
    Example: 
      - /api/bmc?opt=set&type=power&node1=0  ( Will turn off Node 1)
      - /api/bmc?opt=set&type=power&node1=1&node2=1  ( Will turn ON Node 1 and Node 2)

    To reset Network:
      - type (required): "network"
      - cmd (required): Valid values are "reset"
    Example: /api/bmc?opt=set&type=network&cmd=reset

    To OTA Update:
      - type (required): "firmware"
    Example: curl -F 'file=image.swu' 'http://{{host}}/api/bmc?opt=set&type=firmware'

Response:
- 200 OK: The request was successful, and the requested information was returned.

Example Request:
POST/api/bmc?opt=get&type=nodeinfo

Example Response:
{
  "response": [{
    "node1": "unknown",
    "node2": "[jetson]-Ubuntu 18.04.6 LTS BrotherEye ",
    "node3": "unknown",
    "node4": "unknown"
  }]
}