Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create sample with "new" fields #35

Open
SaibotMagd opened this issue Jun 1, 2023 · 3 comments
Open

Create sample with "new" fields #35

SaibotMagd opened this issue Jun 1, 2023 · 3 comments

Comments

@SaibotMagd
Copy link

SaibotMagd commented Jun 1, 2023

Hi,

how can I create a sample using the API when I need the new fields in "Barcodes" (not a template):
image

I can read them with a common "search" query and the result is:

"{'totalHits': 1, 'pageNumber': 0, 
  'records': 
    [{'id': 32794, 'globalId': 'SA32794', 'name': '210076_sample', 'description': '', 
    'created': '2023-05-11T12:47:49.000Z', 'createdBy': 'username', 
    'lastModified': '2023-06-01T09:07:29.035Z', 'modifiedBy': 'username', 
    'modifiedByFullName': 'username', 'deleted': False, 'deletedDate': None, 
    'revisionId': None, 'version': 2, 'historicalVersion': False, 'iconId': -1, 
    'quantity': {'numericValue': 1, 'unitId': 3}, 'tags': '', 'barcode': None, 
  'barcodes': 
    [{'id': 16, 'data': '210075', 'format': None, 'description': 'Scanned Unknown: 210076', 
    'created': '2023-05-11T12:47:49.000Z', 'createdBy': 'username', 
      '_links': 
        [{'link': 'https://rstest.URL/api/inventory/v1/barcodes%3Fcontent=210075&barcodeType=QR', 
        'rel': 'enclosure'}]}]"

I want to create a sample filling the fields in "barcodes".

The definition of the "create_sample" function doesn't help at all: "

def create_sample(
        self,
        name: str,
        tags: Optional[str] = None,
        description: Optional[str] = None,
        extra_fields: Optional[Sequence] = [],
        sample_template_id=None,
        fields=None,
        storage_temperature_min: StorageTemperature = None,
        storage_temperature_max: StorageTemperature = None,
        expiry_date: datetime.datetime = None,
        subsample_count: int = None,
        total_quantity: Quantity = None,
        attachments=None,
    ) -> dict:

"

it seems like there's no direct connection to these fields. So I tried the "fields" parameter but it doesn't have a "barcodes" key. I tried the "extra_fields" parameter but it only works for additional fields created by a template or in addition to the sample creation.

What really puzzles me is that in your sample API description there're no barcodes fields at all. Just the barcode field which is usually empty after creating a sample in the GUI.
image

So I have no idea what to do or where to look at. I'm fine with creating the sample and update the barcode into it afterwards but I can't find a update_sample function to do so.

Can someone help me out?

PS: I direcly asked the rspace support and they said I should build the function I need by myself using the API.

@SaibotMagd
Copy link
Author

Update: Maybe the
class FieldBuilderGenerator: """ Helper class for creating Python classes from SampleTemplates, to help with setting field information into Samples. """
could be a solution.
In the roadmap they mentioned that they included the barcodes as "properties", so it could be something like an hidden internal template!?

image

But how can I create a "field object" and use it to create a sample?

@mKowalski256
Copy link

Hi, the API description is unfortunately out-of-date, as you're saying the barcode field of any inventory item (sample) is empty/unused. What you want to use is the barcodes array, which is not documented but works similarly to extraFields array (check /sample endpoint POST/PUT in documentation to understand how new extra field can be created).

E.g. to create new barcode you need to pass the barcodes array with a new object that has createNewBarcode flag set to true. Example body for PUT endpoint could look like this:
{ "barcodes": [ { "newBarcodeRequest": true, "data": "ABC123" } ] }
Same could be done for POST endpoint that creates the sample, just put barcodes array along the other properties.

@SaibotMagd
Copy link
Author

Thx for your reply. As I try to find out the correct command I crashed the database, but now we´re good to go once more :D . Could you provide the complete command I have to use to insert a new sample with a barcode (just the name and the barcode and maybe a "created timestamp") because I still couldnt find the correct one. Your description above is helpful but incomplete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants