Custom sample-creation fields and value assignment through API

Hello,

From the examples I have found searching through the Senaite Community, it seems that the only fields that can be given values through the ‘/AnalysisRequest/create’ API call are: Contact, DateSampled, SampleType, and Template. Is this the case or can all the fields from the ‘Request new analyses’ page in Senaite be given values through the above call?

Also, I’ve found the recipe to create new columns for a sample listing, but is it possible to create new fields for sample creation to correspond to new columns added to the listing?

My intent is to add custom fields/columns and be able to assign values to them upon sample creation through the API call.

I would appreciate any insight you may have. Thank you for your time.

From the examples I have found searching through the Senaite Community, it seems that the only fields that can be given values through the ‘/AnalysisRequest/create’ API call are: Contact, DateSampled, SampleType, and Template. Is this the case or can all the fields from the ‘Request new analyses’ page in Senaite be given values through the above call?

Values from other existing fields passed through the POST payload on sample (aka “AnalysisRequest”) creation should be processed as usual (as long as they are valid values). You can see in the code that the creation of this type of object ultimately rely on the same function as if you were submititng the Sample Add form: senaite.jsonapi/src/senaite/jsonapi/api.py at 1.x · senaite/senaite.jsonapi · GitHub (note data parameter is the dict of key:value)

Also, I’ve found the recipe to create new columns for a sample listing, but is it possible to create new fields for sample creation to correspond to new columns added to the listing?

You can add custom fields using Archetype’s schema extenders: archetypes.schemaextender — Plone Documentation v4.3

Thank you for the information and resources!

I should have specified that I am using the senaite.jsonapi and the ‘http://localhost:8080/senaite/@@API/senaite/v1/AnalysisRequest/create’ calls. Is there a resource or method to determine all the valid key:value pairs for sample creation? These are the ones I know so far:

{
“Contact”: <client_contact_uid>,
“SampleType”: <sample_type_uid>,
“DateSampled”: “2020-03-05 14:21:20”,
“Template”: <ar_template_uid>,
}

I am most interested in assigning Lab Analyses. I tried a workaround by adding a ‘Template’ (which was created in Senaite with analyses attached) to samples through the above call. However, unlike assigning a Sample Template through the Sample Add form in Senaite itself, assigning one through the jsonapi call did not allow for the Lab Analyses within the Sample Template to show up when the new sample is viewed in Senaite.

Thank you in advance for your help with this.

I discovered that “Analyses” : <tuple of AnalysisSerived uid’s> was able to assign multiple analyses upon sample creation.

I would still very much appreciate any information on how to determine all valid key:value pairs for AnalysisRequest/create.

Thank you for your time