REST API Reference

The TofuPilot REST API is the primary interface for programmatically uploading test runs to TofuPilot.


Authentication

Authenticate your requests to access any endpoints in the TofuPilot API using OAuth2 with your API key.

Add the key to the request header using cURL:

curl https://tofupilot.com/v1/runs/create \
  -H "Authorization: Bearer {api-key}"

Keep your API key safe and regenerate it if you suspect compromise.


POST/v1/runs

Create a run

This endpoint allows you to create a new run.

  • Name
    procedure_id
    Type
    string, required
    Description

    Unique identifier for the procedure.

  • Name
    unit_under_test
    Type
    record, required
    Description

    Record of the unit under test.

  • Name
    serial_number
    Type
    string, required
    Description

    Unit identifier. Creates new unit if no match.

  • Name
    part_number
    Type
    string, optional
    Description

    Component identifier. Creates new component if no match.

  • Name
    revision
    Type
    string, optional
    Description

    Component revision. Required if multiple revisions exist.

  • Name
    run_passed
    Type
    boolean, required
    Description

    Indicates if the run passed.

  • Name
    duration
    Type
    string, required
    Description

    ISO 8601 duration of the run.

  • Name
    started_at
    Type
    string
    Description

    ISO 8601 start time of the run.

  • Name
    steps
    Type
    array, optional
    Description

    Steps of the procedure.

  • Name
    name
    Type
    string, required
    Description

    Step name.

  • Name
    step_passed
    Type
    boolean, required
    Description

    Indicates if the step passed.

  • Name
    started_at
    Type
    string, required
    Description

    ISO 8601 start time of the step.

  • Name
    duration
    Type
    string, required
    Description

    ISO 8601 duration of the step.

  • Name
    measurement_unit
    Type
    string, optional
    Description

    Unit of measurement.

  • Name
    measurement_value
    Type
    float, optional
    Description

    Measured value.

  • Name
    limit_low
    Type
    float, optional
    Description

    Minimum threshold.

  • Name
    limit_high
    Type
    float, optional
    Description

    Maximum threshold.

  • Name
    attachments
    Type
    array(string), optional
    Description

    File paths for attachments.

  • Name
    sub_units
    Type
    array(record), optional
    Description

    Identifiers of sub-units.

  • Name
    serial_number
    Type
    string, required
    Description

    Serial number of sub-unit.

  • Name
    report_variables
    Type
    record(string, string)
    Description

    Key/value pairs for report variables.

Request

POST
/v1/runs
from tofupilot import TofuPilotClient
import time
from datetime import datetime

def test_function():
    # Your test execution goes here
    time.sleep(1)

    run_passed = True
    report_variables = {
      "initial_temperature_reading": "72°C",
      "final_temperature_reading": "75°C",
    }
    attachments = [
      '/mnt/data/temperature-map.png',
      '/mnt/data/performance-report.pdf'
    ]

    return run_passed, report_variables, attachments

# Measure the duration of the test_function
start_time = datetime.now()
run_passed, report_variables, attachments = test_function()
end_time = datetime.now()
duration = end_time - start_time

client = TofuPilotClient(api_key="Your API key goes here")

client.create_run(
    procedure_id="FVT1",
    unit_under_test={
        "serial_number": '00102',
        "part_number": 'PCB01'
    },
    run_passed=run_passed,
    duration=duration,
    report_variables=report_variables,
    attachments=attachments
)

Response

{
  "url": "https://tofupilot.com/acme-corp/runs/your-new-run"
}

Errors

Whenever a request is unsuccessful, the TofuPilot API will return a response with a status code and error message.

Status Codes

Here are the categories of status codes returned by the TofuPilot API:

  • Name
    2xx
    Description

    A 2xx status code indicates a successful response.

  • Name
    4xx
    Description
    A 4xx status code indicates a client error.
  • Name
    5xx
    Description
    A 5xx status code indicates a server error.

Error Messages

Use error messages to identify and fix issues. For example:

Error response

{
  "status_code": 404,
  "message": "No procedure found with ID FVT2",
}

Was this page helpful?