Skip to main content

Update Test Program

POST 

/api/v1/lab-tests/test-program

Saves a new version of the Test Program of the API key's organization. The program is checked and stored as the Test Program page saves it, so a program saved here opens on the page, and a program saved on the page can be read here and sent back.

The request replaces the whole program: read it with Get Test Program, change it, and send it back. Every request that passes the checks saves a new version on top of the current one, whoever saved that one (the page or this API). There is no version check, so when two saves overlap, the last one wins.

enabled is the page's Enabled / Disabled switch: while it is true, the program runs for new lab tests; while it is false, it does not. Left out, the program keeps its setting (true on a first save).

Program format guide: how a program runs, blocks, conditions, fields, actions, edges, labels and checks on save (click to open)

How a program runs​

A Test Program decides which tests a new lab test gets. While the program is enabled, it runs for each new lab test with that lab test's values.

  1. The run starts at the block named by startBlockId.
  2. A Condition block checks its cases against the lab test's values. The run follows the wires (edges) leaving every exit the block takes: a matching case's id, or else when no case matched.
  3. Every Action block the run reaches adds its tests. A block reached by several wires runs once.
  4. The tests of all the Action blocks reached are merged into one list. A property appears once, with every condition any block added. A condition is Required when any of those blocks makes it Required, and Locked when any of them locks it.

For example, this program (the request example Decision tree):

Children's product? (c_kids, yesno)
├─ Yes ─▶ Sold in the EU? (c_eu, yesno)
│ ├─ Yes ─▶ EU children's chemical tests (a_eu_kids) and Children's safety tests (a_kids)
│ └─ No ──▶ Children's safety tests (a_kids)
└─ No ──▶ General quality tests (a_general)

gives a children's product sold in the EU the tests of a_eu_kids and a_kids, a children's product sold elsewhere those of a_kids, and any other product those of a_general.

Building a definition​

  1. Pick the blocks. A question with two answers is a yesno block; a question with several answers is a branch block with one case per answer; each set of tests to add is an action block.
  2. Give every block, case and edge an id that is unique in the program, for example c_eu for a block, c_eu_yes for its case, e1 for a wire. Give every block a title; titles must differ too.
  3. Write each case's condition from the fields below.
  4. Wire the blocks. Each edge leaves a Condition block through one exit (port: a case id, or else) and goes into the next block. Action blocks end a path.
  5. Set startBlockId to the one Condition block no wire goes into.

Blocks​

TypeWhat it doesExits (port of the wires leaving it)
yesnoYes / No. Exactly one case and hasElse: true. The case matches: Yes; it does not: No.Yes = the case id; No = else
branchChecks its cases in order and takes the exit of every case that matches. A matching case with stopHere: true stops the check: the cases after it are not checked. When no case matched, it takes Anything Else (only with hasElse: true).each case id, and else with hasElse: true
actionAdds tests: one add_tests_by_ids and/or one add_tests_by_tags in actions.none

Condition blocks: every shape​

A Yes / No block, as the page saves it. Its one case has no label or stopHere, and hasElse is always true (the No exit):

{ "id": "c_line", "type": "yesno", "title": "Has a product line?", "hasElse": true,
"cases": [
{ "id": "c_line_yes",
"condition": { "combinator": "and", "groups": [
{ "id": "g1", "combinator": "and", "conditions": [
{ "id": "r1", "field": { "key": "product_line", "fieldType": "system" }, "operator": "isNotEmpty" } ] } ] } } ] }

A Branch block. Each case has a label (its name on the page) and stopHere; hasElse turns Anything Else on or off:

{ "id": "c_attr", "type": "branch", "title": "Item attributes", "hasElse": false,
"cases": [
{ "id": "c_attr_yes", "label": "Size S", "stopHere": false,
"condition": { "combinator": "and", "groups": [
{ "id": "g1", "combinator": "and", "conditions": [
{ "id": "r1", "field": { "key": "size", "fieldType": "system" },
"operator": "isAnyOf", "value": [ "S" ] } ] } ] } },
{ "id": "c_attr_case_2", "label": "Category 1", "stopHere": false,
"condition": { "combinator": "and", "groups": [
{ "id": "g2", "combinator": "and", "conditions": [
{ "id": "r2", "field": { "key": "product_category", "fieldType": "system" },
"operator": "isAnyOf",
"value": [ { "id": "Tax-PC-1-Custom-ID", "label": "Taxonomy Product Category 1" } ] } ] } ] } } ] }

Case ids are any text unique in the program. The page names them <block id>_yes on a Yes / No block and <block id>_case_<n> on a Branch; a Yes / No block switched to a Branch keeps its _yes case, as above.

What the run does after each block:

BlockIts condition resultThe run follows
Yes / Nothe case matchesthe wires from the case id (Yes)
Yes / Nothe case does not matchthe wires from else (No); none wired: this path ends
Branch, hasElse: falsecases 1 and 2 matchthe wires of case 1 and case 2
Branch, hasElse: falseno case matchesnothing: this path ends
Branch, hasElse: trueno case matchesthe wires from else (Anything Else)
Branch, hasElse: trueany case matchesthat case's wires; else is not followed
Branchcase 1 (stopHere: true) matchesthe wires of case 1 only; later cases are not checked
Branchcase 1 (stopHere: true) does not matchthe check goes on to case 2

Every case needs at least one row. A case without rows is refused with 400 (yesno.no_condition, branch.case_no_condition), as the page does not let one be drawn.

Conditions​

A case's condition has two levels: the rows of a group are joined by the group's combinator (and / or), and the groups by the condition's combinator. (A and B) or C is:

{ "combinator": "or", "groups": [
{ "combinator": "and", "conditions": [ A, B ] },
{ "combinator": "and", "conditions": [ C ] } ] }

A row is { "id", "field", "operator", "value" }. The three shapes of value:

OperatorValueExample row
isEmpty, isNotEmptyleave it out{ "field": { "key": "product_line", "fieldType": "system" }, "operator": "isNotEmpty" }
is, isNot, gt, gte, lt, lteone value{ "field": { "key": "po_total_cost", "fieldType": "system" }, "operator": "gte", "value": 10000 }
isAnyOf, isNoneOfa non-empty list{ "field": { "key": "size", "fieldType": "system" }, "operator": "isAnyOf", "value": [ "S", "M" ] }

A value is either plain ("S", 10000, "2026-01-01") or an option { "id", "label" }. Only id is compared; label is what the page shows. The page saves typed text as plain values and a choice picked from a list as an option, and both work the same way. Organization values always take { "id", "label" }.

OperatorMatches when the field …
is / isNotis / is not the value
isAnyOf / isNoneOfis one / none of the values
gt / gte / lt / lteis greater / greater or equal / less / less or equal (numbers and dates)
isEmpty / isNotEmptyhas no value / has a value
  • A field can hold several values (size of a lab test with several items). is, isAnyOf and the comparisons match when any value matches; isNot and isNoneOf match when no value is one of the values given.
  • Values are compared exactly: texts with their case, numbers as numbers (10000, not "10000"), dates as YYYY-MM-DD.
  • A field with no value matches only isEmpty, never isNot or isNoneOf. For "not X, or empty", put isNoneOf X and isEmpty in one group joined by or.

Fields​

A system field is { "key", "fieldType": "system" }. An operator the field does not list is refused with 400 (condition.parse, reason: operator_not_allowed). Sample value is what a row sends for the first operator listed.

Test / Request Information

KeyLabelHoldsAvailable operatorsSample value
process_typeProcess Typechoice: lab_test, approval_requestis isNot isAnyOf isNoneOf"lab_test"
lab_test_typeLab Test / Request Typethe type's uuid (Lab Test Rule Settings)is isNot isAnyOf isNoneOf{ "id": "6b1f3c2e-8a4d-4e7b-9c1a-2d5e8f7a9b10", "label": "Chemical Test" }
lab_test_formLab Test / Request Formthe form's id, as textis isNot isAnyOf isNoneOf{ "id": "1245", "label": "Chemical Lab Test Form" }
test_receiverTest / Request Receiverorganization: Local Organization ID (see Organization values)is isNot isAnyOf isNoneOf{ "id": "LAB-HCM-01", "label": "Lab A - Ho Chi Minh" }
test_creatorTest / Request Creatororganization: Local Organization ID (see Organization values)is isNot isAnyOf isNoneOf{ "id": "VEN-001", "label": "Vendor One" }
test_serviceTest ServicetextisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ "Regular" ]
stage_of_testingStage of TestingtextisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ "Pre-production" ]
remarkRemarktextisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ "Urgent" ]
production_dateProduction Datedategte gt lte lt is isNot isEmpty isNotEmpty"2026-01-01"
expected_completion_dateExpected Completion Datedatelte lt gte gt is isNot isEmpty isNotEmpty"2026-12-31"
tagTagchoice: 1st Re-test … 5th Re-test, Has Re-testisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ "Has Re-test" ]
statusStatuschoice: draft, new, confirmedis isNot isAnyOf isNoneOf"new"
created_dateCreated Datedategte gt lte lt is isNot"2026-11-01"
updated_dateUpdated Datedategte gt lte lt is isNot"2026-11-01"

tag, status, created_date and updated_date have no value yet when the program chooses tests, so a row on them never matches (except tag with isEmpty, which always does).

Product Classification. The taxonomy fields hold the Custom ID of the item's category at that taxonomy level; label is the category's name.

KeyLabelHoldsAvailable operatorsSample value
product_typeProduct Typechoice: Item, Style, Materialis isNot isAnyOf isNoneOf"Item"
groupGroupcategory Custom IDisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "GRP-APPAREL", "label": "Apparel" } ]
divisionDivisioncategory Custom IDisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "DIV-KIDS", "label": "Kids" } ]
departmentDepartmentcategory Custom IDisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "DEP-TOYS", "label": "Toys" } ]
classClasscategory Custom IDisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "CLS-PLUSH", "label": "Plush Toys" } ]
product_lineProduct Linecategory Custom IDisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "PL-BABY", "label": "Baby" } ]
product_categoryProduct Categorycategory Custom IDisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "Tax-PC-1-Custom-ID", "label": "Taxonomy Product Category 1" } ]
brandBrandcategory Custom IDisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "BR-OWN", "label": "Own Brand" } ]
material_typeMaterial Typecategory Custom IDisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "MT-FABRIC", "label": "Fabric" } ]
material_categoryMaterial Categorycategory Custom IDisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "MC-WOVEN", "label": "Woven" } ]
material_sub_categoryMaterial Sub-categorycategory Custom IDisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "MSC-DENIM", "label": "Denim" } ]

Product Attributes

KeyLabelHoldsAvailable operatorsSample value
colorColortextisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ "Red" ]
sizeSizetextisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ "S" ]
country_of_originCountry of Origin2-letter ISO country codeisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "VN", "label": "Vietnam" } ]
sample_sizeSample Sizenumbergte gt lte lt is isNot isEmpty isNotEmpty10
sample_uomSample UOMtextisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ "pcs" ]

Purchase Order

KeyLabelHoldsAvailable operatorsSample value
po_numberPO NumbertextisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ "PO-2026-0001" ]
opo_numberOPO NumbertextisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ "OPO-2026-0001" ]
po_typePO Typethe PO type's descriptionisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "Bulk Order", "label": "Bulk Order" } ]
po_ship_begin_datePO Ship Begin Datedategte gt lte lt is isNot isEmpty isNotEmpty"2026-03-01"
po_ship_end_datePO Ship End Datedategte gt lte lt is isNot isEmpty isNotEmpty"2026-03-31"
po_in_store_datePO In Store Datedategte gt lte lt is isNot isEmpty isNotEmpty"2026-05-01"
po_confirmation_datePO Confirmation Datedategte gt lte lt is isNot isEmpty isNotEmpty"2026-01-15"
po_approval_datePO Approval Datedategte gt lte lt is isNot isEmpty isNotEmpty"2026-01-20"
po_commit_idPO Commit IDtextisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ "CMT-001" ]
po_commit_po_sequencePO Commit PO SequencetextisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ "1" ]
po_total_costPO Total Costnumbergte gt lte lt is isNot isEmpty isNotEmpty10000
po_cost_currencyPO Cost CurrencyISO 4217 currency codeisAnyOf isNoneOf is isNot isEmpty isNotEmpty[ { "id": "EUR", "label": "EUR" } ]

Stakeholders. Every stakeholder has the same set of fields. A field's key is the stakeholder's key prefix followed by a field name from the second table: supplier_tier_1_ + city = supplier_tier_1_city, factory_ + country = factory_country.

StakeholderKey prefixLabel prefixReadsIts fields
Brand / Retailerbrand_retailer_(Brand / Retailer)the Brand / Retailerall 13 fields of the next table
Suppliersupplier_(Supplier)the first supplier with no tierall 13 fields of the next table
Supplier - Tier 1supplier_tier_1_(Supplier - Tier 1)the first supplier of tier 1all 13 fields of the next table
Supplier - Tier 2supplier_tier_2_(Supplier - Tier 2)the first supplier of tier 2all 13 fields of the next table
Supplier - Tier 3supplier_tier_3_(Supplier - Tier 3)the first supplier of tier 3all 13 fields of the next table
Factoryfactory_(Factory)the first factory with no tierall 13 fields of the next table
Factory - Tier 1factory_tier_1_(Factory - Tier 1)the first factory of tier 1all 13 fields of the next table
Factory - Tier 2factory_tier_2_(Factory - Tier 2)the first factory of tier 2all 13 fields of the next table
Factory - Tier 3factory_tier_3_(Factory - Tier 3)the first factory of tier 3all 13 fields of the next table
Lab Test Agencylab_test_agency_(Lab Test Agency)the Lab Test Agencyall 13 fields of the next table
Billing Informationbilling_(Billing Information)the Billing Information9 fields: the next table without organization_id, organization_name, sub_organization_id, sub_organization_name

The 13 fields of a stakeholder, shown with the keys of Supplier - Tier 1 (every field offers isAnyOf isNoneOf is isNot isEmpty isNotEmpty):

Key (Supplier - Tier 1)LabelHoldsSample value
supplier_tier_1_organizationOrganizationorganization: Local Organization ID (see Organization values below)[ { "id": "SUP-HCM-01", "label": "Supplier A - Ho Chi Minh" } ]
supplier_tier_1_organization_idLocal Organization IDthe local organization's Custom ID, as text[ "SUP-HCM-01" ]
supplier_tier_1_organization_nameLocal Organization Nametext[ "Supplier A - Ho Chi Minh" ]
supplier_tier_1_sub_organization_idSub-Organization IDthe sub-organization's Custom ID; filled only on a card set to pick a sub-organization[ "SUP-HCM-01-D1" ]
supplier_tier_1_sub_organization_nameSub-Organization Nametext; same condition[ "Supplier A - Dyeing Unit" ]
supplier_tier_1_cityCitytext[ "Ho Chi Minh City" ]
supplier_tier_1_state_provinceState / Provincetext[ "Ho Chi Minh" ]
supplier_tier_1_postal_zip_codePostal / Zip Codetext[ "700000" ]
supplier_tier_1_countryCountry2-letter ISO country code[ { "id": "VN", "label": "Vietnam" } ]
supplier_tier_1_contact_nameContact Nametext[ "An Nguyen" ]
supplier_tier_1_contact_emailContact Emailtext[ "[email protected]" ]
supplier_tier_1_contact_phone_numberContact Phone Numbertext[ "+84 28 1234 5678" ]
supplier_tier_1_contact_mobile_numberContact Mobile Numbertext[ "+84 90 123 4567" ]

For another stakeholder, change the prefix: factory_city, brand_retailer_country, lab_test_agency_contact_email, billing_organization.

Organization values. Three kinds of field hold an organization rather than text: test_receiver, test_creator, and each stakeholder's …_organization field (brand_retailer_organization, supplier_organization, supplier_tier_1_organization … factory_tier_3_organization, lab_test_agency_organization, billing_organization).

  • Each value is { "id", "label" }, one object for a one-value operator and a list for a list operator. In the request and the response, id is a Local Organization ID of your organization (the localOrganizationId of the Create Lab Test API) and label is that local organization's name.
  • A value whose id is not one of your Local Organization IDs, or whose local organization is not linked to a global organization, is refused with 400 (condition.parse, reason: invalid_value). This includes "id": null.
  • In a response, id is null and label is the saved organization name when a value saved on the page matches none, or more than one, of your local organizations. Replace such a value before sending the program back.
  • The other stakeholder fields (…_organization_id, …_organization_name, …_sub_organization_…, addresses, contacts) are plain text, compared as you send it.

Additional fields are the organization's own data fields: \{ "key", "fieldType": "additional_field", "entityType" \}.

Entity typeReadsKey isData types
lab_testa Lab Test Additional Data field, answered on the lab test formthe field's name, exactly as written (it may hold spaces)text, date
itman Item data fieldthe data field's IDtext, number, date, choice
pdta Style data fieldthe data field's IDtext, number, date, choice
mata Material data fieldthe data field's IDtext, number, date, choice
poa Purchase Order data fieldthe data field's IDtext, number, date, choice

A data field with choices (Single / Multiple Selection) is a choice field: its value is the choice itself, and the "Other" choice is __OTHER__. Text and choice fields offer isAnyOf isNoneOf is isNot isEmpty isNotEmpty; number and date fields offer gte gt lte lt is isNot isEmpty isNotEmpty. Sample rows (the field names are examples; use your organization's):

Field (label on the page)Field objectData typeSample row
(Lab Test) Season{ "key": "Season", "fieldType": "additional_field", "entityType": "lab_test" }text"operator": "isAnyOf", "value": [ "SS26", "FW26" ]
(Lab Test) Ship Date{ "key": "Ship Date", "fieldType": "additional_field", "entityType": "lab_test" }date"operator": "gte", "value": "2026-06-01"
(Item) Destination Markets{ "key": "DEST_MARKETS", "fieldType": "additional_field", "entityType": "itm" }choice"operator": "isAnyOf", "value": [ "EU", "UK" ]
(Item) Net Weight (g){ "key": "ITEM_NET_WEIGHT", "fieldType": "additional_field", "entityType": "itm" }number"operator": "gt", "value": 250
(Style) Fit{ "key": "STYLE_FIT", "fieldType": "additional_field", "entityType": "pdt" }text"operator": "is", "value": "Slim"
(Material) Fiber Content{ "key": "MAT_FIBER", "fieldType": "additional_field", "entityType": "mat" }choice"operator": "isAnyOf", "value": [ "Cotton", "__OTHER__" ]
(Material) Certificate Expiry{ "key": "MAT_CERT_EXPIRY", "fieldType": "additional_field", "entityType": "mat" }date"operator": "lt", "value": "2027-01-01"
(PO) Season Code{ "key": "PO_SEASON", "fieldType": "additional_field", "entityType": "po" }text"operator": "isNoneOf", "value": [ "CLEARANCE" ]
(PO) Order Quantity{ "key": "PO_ORDER_QTY", "fieldType": "additional_field", "entityType": "po" }number"operator": "gte", "value": 5000

Actions​

add_tests_by_ids names the tests by their IDs: a package's id is its Test Package ID, a property's its Test Property ID, and a condition's its Test Condition ID on the property's latest version. Every id is a text: a number (such as 12) is refused, and the text "12" is looked up as an ID.

{ "name": "add_tests_by_ids",
"arguments": {
"packages": [ { "id": "CHM-EU-01", "properties": [
{ "id": "CHM-PB-01", "conditions": [ { "id": "L-01", "locked": true } ] } ] } ],
"properties": [ { "id": "CHM-CF-01", "conditions": [ { "id": "C-01", "required": true }, { "id": "C-02" } ] } ] } }
  • properties adds properties on their own; packages adds properties as part of a package (each listed property must belong to it). Only what is listed is added, not the rest of the package.
  • Every package lists at least one property, every property at least one condition.
  • packages or properties may be an empty list (the page sends "properties": []) when the other one lists something.
  • required: true / false overrides the condition's catalog setting; left out, the catalog setting applies. locked: true: the condition cannot be removed from a lab test the program filled.

add_tests_by_tags adds what the tags select, from the catalog as it is when the program runs:

{ "name": "add_tests_by_tags",
"arguments": {
"packages": { "operator": "anyOf", "values": [ "EU" ],
"properties": { "operator": "noneOf", "values": [ "discontinued" ] } },
"properties": { "operator": "allOf", "values": [ "chemical", "children" ] },
"conditions": { "operator": "anyOf", "values": [ "always run" ] } } }
SectionAddsMay hold a limit
packagesevery package whose tags match, with its properties and their conditionsproperties, which may hold conditions
propertiesevery property whose tags match, with its conditionsconditions
conditionsin every property, the conditions whose tags matchnone

anyOf = has at least one of the tags, allOf = has all of them, noneOf = has none. Tags are compared ignoring case and repeated spaces. Only enabled, visible packages and properties are used; a condition's Required is its catalog setting, and none is Locked.

Edges​

{ "id", "from", "port", "to" }: when the run leaves block from through exit port, it goes on to to.

  • from is a Condition block, and port one of its case ids, or else when it has hasElse: true.
  • Several wires may leave the same exit; all are followed. Several may come into the same block; it runs once.
  • Wires may not form a loop.
  • Exactly one Condition block has no wire coming in: it is startBlockId. An Action block with no wire coming in never runs (warning graph.unreachable).

Labels​

name (packages, properties, conditions) and a field's label are optional. On save they are written from the catalog and the field list for every id found. An id that is not found keeps what was sent and adds an add_tests.not_found warning; the program is still saved.

Checks on save​

Errors refuse the program with 400; nothing is saved.

CodeMeaning
graph.schemaThe definition cannot be read; params.reason says why (below).
graph.no_startThere are blocks, but no Condition block to start from, or startBlockId is null.
graph.multiple_startsMore than one Condition block has no wire coming in.
graph.cycleThe wires form a loop.
graph.duplicate_namesTwo blocks have the same title.
yesno.no_conditionA Yes / No block's case has no rows.
branch.case_no_conditionA Branch case has no rows.
condition.parseA row cannot be checked: operator_not_allowed, value_not_allowed, or invalid_value (an organization value; see Organization values).

graph.schema reasons: unsupported_schema_version, start_mismatch (startBlockId is not the block no wire goes into), invalid_blocks / invalid_edges (not a list), invalid_block, invalid_title, invalid_description, duplicate_id, unknown_block_type, invalid_yesno, invalid_value, nested_group, unknown_operator, invalid_field, unknown_action, duplicate_action, empty_selection, empty_tags, invalid_level, invalid_edge, edge_from_missing_block, edge_to_missing_block, invalid_port, duplicate_edge.

Warnings do not stop the save; they come back in warnings. Check them: some mean part of the program can never run.

CodeMeaning
condition.unknown_fieldA row reads a field that is not in the field list (for example a misspelled key); it matches only isEmpty.
condition.unknown_optionA choice the field does not list.
add_tests.not_foundA package, property or condition id that is not in the catalog.
graph.unreachableAn Action block no path reaches.
graph.no_actionsThe program has no Action block.
yesno.unwiredNeither exit of a Yes / No block is wired.
branch.no_casesA Branch block without cases.
branch.case_unwiredA Branch case leads nowhere.
branch.else_unwiredAnything Else is on, but nothing is wired to it.

Request​

Responses​

The saved version, with warnings