Create Lab Test
POST/api/v1/lab-tests
Lab Test Creation Modes
Create a new Lab Test. When status is not sent (or is null), the system decides between three creation modes based on provided data:
Submitted Test Creation:
- Provide all required test result fields: sampleReceiptDate, reportIssueDate, reportNumber, testProperties, and overallResult
- Creates a lab test with "submitted" status, or "completed" when the Lab Test Form completes tests automatically
- All provided data is saved
New Test Creation:
- Omit test result fields but provide all required fields specified in the Lab Test Form
- Creates a lab test with "new" status. When the Lab Test Form confirms tests automatically, the status is "confirmed"
- Test Packages and Test Properties are kept as described in "Test Packages and Test Properties on New and Draft Creation" below
- The following data is discarded: sampleReceiptDate, reportIssueDate, reportNumber, originalReportNumber, revisionNumber, overallResult, and testReport type attachments
- Non-report attachments are preserved
Draft Test Creation:
- Omit test result fields AND one or more required fields from the Lab Test Form
- Creates a lab test with "draft" status
- Test Packages and Test Properties are kept as described in "Test Packages and Test Properties on New and Draft Creation" below
- The following data is discarded: sampleReceiptDate, reportIssueDate, reportNumber, originalReportNumber, revisionNumber, overallResult, and testReport type attachments
- Non-report attachments are preserved
Test Packages and Test Properties on New and Draft Creation:
- They are kept only when the Test Requirements component is active on the creation tab of the Lab Test Form. Otherwise every Test Package and Test Property in the request is discarded
- A Test Package or Test Property (matched by
id) is kept when it is enabled on the platform and is available to the organization that sends the creation API request - A kept Test Package adds all of its current Test Properties, at their latest version
- Kept Test Packages stay on the lab test even when
testPropertiesis empty or not sent, so a request with Test Packages only keeps them - A kept Test Property is linked to its latest version and all of that version's Test Conditions. It is shown under its
testPackageIdwhen that is a kept Test Package containing it, and under "Additional Test Properties" otherwise - Test results are not saved:
result,reviewResult, and thetestConditionsof a Test Property'sitems/materials/stylesare ignored. Whenstatusis sent, the Test Property's owntestConditionsis applied (see "Test Conditions of a Test Property") - Test Packages and Test Properties that are not kept are discarded, and the lab test is still created with the kept ones
- Whether the Test Requirements component is mandatory does not change the creation mode
Discarded data in the response:
- On New and Draft creation,
messagelists only the fields that were sent and discarded. Discarded Test Packages and Test Properties are listed with their IDs, for exampletestPackages (PKG-9), testProperties (TP-3, TP-7). Kept ones are not listed messageis omitted when nothing that was sent was discarded
Explicit Creation Status
Send status to choose the creation mode instead of letting the system decide it. labTestStatus in the response is the status of the lab test once it is created, after the Lab Test Form's automatic confirmation or completion.
status = submitted:
- sampleReceiptDate, reportIssueDate, reportNumber, testProperties and overallResult are required, as are all mandatory creation fields of the Lab Test Form
- Creates a lab test with "submitted" status, or "completed" when the Lab Test Form completes tests automatically
- All provided data is saved
status = new:
- All mandatory creation fields of the Lab Test Form are required
- Creates a lab test with "new" status, or "confirmed" when the Lab Test Form confirms tests automatically
- Data is kept and discarded as on New Test Creation above, and Test Packages and Test Properties are kept as described in "Test Packages and Test Properties on New and Draft Creation"
status = draft:
- Mandatory creation fields of the Lab Test Form are not required
- Creates a lab test with "draft" status. Data is kept and discarded as on Draft Test Creation above
When something required is missing:
- The request is rejected with HTTP 400 and the lab test is not created. Nothing is discarded
missingFieldslists every missing field:fieldis where it belongs in the request (for examplefactories[0].contacts[0].emailoritems[1].itemName), andformFieldis the Lab Test Form field that makes it mandatory (for examplestakeholderInformation (factory) > mainContactStakeholder > email). The test result fields have noformField- Format errors, such as an invalid date, are reported first.
missingFieldsis checked only once there are none
Any value other than draft, new or submitted is rejected with HTTP 400.
Test Conditions of a Test Property
testProperties[].testConditions lists which Test Conditions of a Test Property the lab test keeps. It is read only when status is sent; without status it is ignored and not checked. When it is left out or null, nothing changes: on Draft and New the Test Property keeps every Test Condition of its latest version, and on Submitted the Test Conditions come from items / materials / styles.
Matching:
- Every entry must have a Test Condition ID (
id). Entries are matched byidonly (exact match) - A Test Property created on the platform: each
idmust be a Test Condition of its latest version.nameis not used. A Test Condition with no Test Condition ID cannot be listed - A Test Property that is not on the platform (
status=submittedonly): anidthat is a Test Condition of the Test Property's latest version keeps that Test Condition. Any otheridcreates a Test Condition for this lab test with thatidand the entry'sname, which is then required. It is created Required, with input method Test Result - The kept Test Conditions keep their catalog order and settings (Required / Optional, input method, value range, follow-up actions), whatever the order of the request. The choice applies to every item, material or style
status = draft or new:
- Only the listed Test Conditions are kept, also for a Test Property that a kept Test Package brings. When the lab test is started, every item gets only those Test Conditions
- A Test Property that is discarded is reported as discarded and its
testConditionsis ignored
status = submitted:
- Every Test Condition under
items/materials/stylesof that Test Property must match a listed one byid - Every listed Test Condition must have a
resultfor each item / material / style of that Test Property. Partial results are not accepted
Rejected with HTTP 400, and the lab test is not created, when for a kept Test Property:
testConditionsis[]- an entry has no
id - an
idis not a Test Condition of the latest version, on a Test Property created on the platform, or without anameto create it on a Test Property that is not on the platform - the same
idis listed twice status=submitted: a Test Condition underitems/materials/stylesis not intestConditions, or a listed Test Condition has noresultfor an item / material / style
invalidTestConditions lists every error with the Test Property ID, the Test Condition ID or name, and the item, material or style ID for a Test Condition under items / materials / styles. When fields are also missing, missingFields is in the same response.
When the Lab Test Form selects tests Automatically with an active Test Program, the Test Program decides the tests instead of testConditions. See "Tests Set by the Test Program".
The Upload/Update Pre-Created Lab Test API (PUT) does not read testConditions on a Test Property.
Tests Set by the Test Program
When status is sent and the Lab Test Form selects tests Automatically with an active Test Program, the Test Program decides the lab test's Test Packages, Test Properties and Test Conditions. This replaces the rules for Test Packages and Test Properties above, for every status.
What the lab test gets:
- The Test Packages and Test Properties the Test Program picks, each Test Property at its latest version with only the picked Test Conditions, and each condition's Required and Locked as the Test Program sets them
testPackages,testPropertiesand thetestConditionsof each Test Property are only compared with the Test Program's tests. They are not checked against the catalog and nothing is created from them
status = submitted:
- A Test Property's
resultandreviewResult, and a Test Condition result under itsitems/materials/styles, are saved when the Test Program picks that Test Property and that Test Condition - Any other result is rejected with HTTP 400 and the lab test is not created.
refusedResultslists every refused result: the Test Property ID, and for a condition result the item / material / style ID and the Test Condition ID - Every Test Property the Test Program picks must have a
result, and every Test Condition it picks for that Test Property must have aresultfor each item / material / style of the lab test. If any of them has noresultin the request, the request is rejected with HTTP 400 and the lab test is not created missingResultslists each test without a result: the Test Property ID, and for a Test Condition the item / material / style ID and the Test Condition ID. For example{ "testPropertyId": "PHYS-SPR-01", "field": "result" }and{ "testPropertyId": "PHYS-SPR-01", "itemId": "ITEM-1", "testConditionId": "C-01", "field": "result" }- When the request has both refused results and tests without a result, one HTTP 400 lists both, in
refusedResultsandmissingResults
Response:
discardedlists each Test Package, Test Property and Test Condition of the request that the Test Program did not pick. The conditions of a discarded Test Property are not listed againmessagethen ends with "The tests were set by the Test Program of the Lab Test Form. Tests in the request that it did not pick were discarded. See discarded."
Requests without status, forms that select tests Manually, forms without the test selection setting, and forms whose Test Program is deactivated or not set are not affected.
Request​
Responses​
- 201
- 400
- 401
Lab Test Created Successfully
Bad Request
Unauthorized