Eco line MES API

Line gate for Ernie at the Shunde plant. This page and GET /health need no token. Every other route needs Authorization: Bearer <token>. The token is on the server in /etc/eco-mes/env. It is not shown here.

Port 443 uses a Let's Encrypt certificate for this IP. It lasts about six days and the server renews it. Browsers should show a lock. curl does not need -k.

Calls

MethodPathAuthWhat it does
GET/healthnoLiveness. {"ok": true}
GET/ or /docsnoThis page
POST/v1/flowyesMay this station scan this serial?
POST/v1/runsyesStore one finished run
POST/v1/linksyesLink critical components
GET/v1/units/{serial}/historyyesIdentity, runs, active links
GET/v1/units/{serial}/childrenyesActive component serials

Stations

The name must start with one of these. Lane names such as Ernie Functional 4 match.

PrefixFlowOn a stored run
Ernie Functional Always allowed when the serial matches. The first scan creates the unit. PASSED or FAILED. A later PASSED clears an earlier fail.
Ernie Linker Needs a qualifying functional PASSED. Does not create units. Writes links. Does not post a run.
Ernie Provisioning Needs that functional PASSED, every required BOM ref linked, the console not locked, and no provisioning PASSED newer than the last deprovisioning PASSED. PASSED releases the unit. Packing is not a station in this API.
Ernie Deprovisioning Allowed when the unit exists. Stations are not expected to call flow. PASSED returns the unit to provisioning. Links stay.

POST /v1/flow

{
  "station": "Ernie Functional TLA 1",
  "serial": "MC52635A5US010014"
}

A business reject is HTTP 200 with status.code = ERROR. The station shows status.message as-is. HTTP 401 means the token is missing or wrong.

{
  "status": {"code": "OK", "message": ""},
  "error": null,
  "error_code": null,
  "state": "born",
  "created": true,
  "missing": []
}
curl -k -X POST https://HOST/v1/flow \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"station":"Ernie Functional TLA 1","serial":"MC52635A5US010014"}'

POST /v1/runs

{
  "serial": "MC52635A5US010014",
  "station": "Ernie Functional TLA 1",
  "operator": "1001",
  "start_time": "2026-10-26T18:00:00Z",
  "end_time": "2026-10-26T18:04:00Z",
  "status": "PASSED",
  "idempotency_key": "station-run-id",
  "test_steps": {
    "Test Evaluation": [
      {"name": "Check Oscar Secure State 1", "status": "PASSED", "value": 1}
    ]
  }
}

status is PASSED or FAILED. idempotency_key is required. The same key again returns HTTP 200 with duplicate: true and the same run_id. test_steps is stored whole. A provisioning run that includes Check Oscar Secure State 1 with status PASSED locks the console even when the overall run is FAILED.

An illegal result is HTTP 409 with error REQUEST_REJECTED. Do not retry that body. A missing or unknown station, a bad timestamp, or a non-object body is HTTP 400.

POST /v1/links

{
  "parent_serial": "MC52635A5US010014",
  "operator": "1001",
  "components": [
    {"ref_designator": "MLB", "component_serial": "C260500001"}
  ]
}

The unit must already exist and functional must have a qualifying PASSED. A PCBA serial P YY WW XXXXX with P in CLHS fills the decode columns. Any other component serial still links, with those columns null. When every required BOM ref is present, state becomes linked.

GET history and children

curl -k https://HOST/v1/units/MC52635A5US010014/history \
  -H "Authorization: Bearer $TOKEN"

History returns identity, runs in ended_at order, and active links. Unknown serial is HTTP 404. Children returns {"serial", "components": [{"ref_designator", "component_id"}]}.

Error codes

On /v1/flow these are HTTP 200 with status.code = ERROR and error = FLOW_ERROR.

error_codemessage
INVALID_SERIALSerial number does not match the Ernie format.
UNKNOWN_SERIALThis serial has not been scanned at functional.
NO_FUNCTIONALFunctional has not passed for this serial.
FUNCTIONAL_FAILEDLatest functional result is FAILED. Run functional again.
NOT_LINKEDCritical components are not linked.
MISSING_REFSMissing components, then the ref names.
ALREADY_PROVISIONEDThis unit is already provisioned.
CONSOLE_LOCKEDConsole is locked. Run deprovisioning before provisioning again.
COMPONENT_IN_USEComponent serial is already linked to another unit.
UNKNOWN_STATIONUnknown station.

Serial shape

Unit, example MC52635A5US010014: company CL|M|A, location SGAEC, build code 1-9MWR, year, week, product id A5, country, revision, four-digit sequence.

PCBA, example C260500001: C MLB, L button LED, H hall, S SHT40, then year, week, five-digit sequence.

States

born, functional_passed, functional_failed, linked, provisioned, deprovisioned.

Ernie stations are not wired to this service. A failed check here does not stop the line.