Unable to create analysis service using the API

Hey all, I am trying to create an analysis service using the API. Here is the JSON payload I’m sending.

{
“portal_type”: “AnalysisService”,
“Category”: {
“uid”: “6081d7c72450451fad4dd9128cf979de”
},
“title”: “red blood cell”,
“Keyword”: “red-bc”,
“ScientificName”: true,
“Price”: “15.00”,
“Accredited”: true,
“parent_path”: “/senaite/bika_setup/bika_analysisservices”
}

When I try to send this payload I get this response?
{
“_runtime”: 0.1591191291809082,
“message”: “object of type ‘NoneType’ has no len()”,
“success”: false
}
I’m following the pattern from the create.rst file in the Senaite JSON repo.

data = {“portal_type”: “AnalysisService”,
… “parent_path”: api.get_path(setup.bika_analysisservices),
… “title”: “Salmonella”,
… “Keyword”: “Sal”,
… “ScientificName”: True,
… “Price”: 15,
… “Category”: api.get_uid(category),
… “Accredited”: True}
sal = create(data)
sal.Title()
‘Salmonella’
sal.getKeyword()
‘Sal’
sal.getScientificName()
True
sal.getAccredited()
True
sal.getCategory()
<AnalysisCategory at /plone/bika_setup/bika_analysiscategories/analysiscategory-1>

What am I doing wrong?

Hi @blaine,

it looks to me like the Category value should be just the UID, e.g.:

{
...
    "Category": "6081d7c72450451fad4dd9128cf979de"
...
}

https://senaitejsonapi.readthedocs.io/en/latest/crud.html#create

This is how I create them via Python/API:

global BASE_URL
BASE_URL = “http://” + ip + “:” + port + “/”
global API_URL
API_URL = BASE_URL + SITE_ID + “/@@API/senaite/v1/”

data = { "portal_type": "AnalysisService",
             "parent_path": "/senaite/bika_setup/bika_analysisservices",
             "title": "<the name you want>",
             "Keyword": "<unique keyword>",
             "PointOfCapture": "lab",
             "Category": "<you need to have the uid of the category>"
       }
        requests.post(API_URL+"/create", headers=headers, json=data, auth=AUTH)

After trying this approach I got this error:
{
“_runtime”: 0.1815950870513916,
“message”: “{“UpperDetectionLimit”: “Validation failed(isDecimal): 1000000000.0 of type <type ‘float’>, expected ‘string’”, “LowerDetectionLimit”: “Validation failed(isDecimal): 0.0 of type <type ‘float’>, expected ‘string’”}”,
“success”: false
}

Can u show me the payload you sent?

Here it is
{ “portal_type”: “AnalysisService”,
“parent_path”: “/senaite/bika_setup/bika_analysisservices”,
“title”: “red blood cell”,
“Keyword”: “red-bc”,
“PointOfCapture”: “lab”,
“Category”: “6081d7c72450451fad4dd9128cf979de”
}

I don’t think Senaite allows you to insert keywords that contain special characters (e.g. -), so please try to use a different keyword just for testing i.e. redBc

I did as you suggested and I got this error
{
“_runtime”: 0.1819760799407959,
“message”: “{“UpperDetectionLimit”: “Validation failed(isDecimal): 1000000000.0 of type <type ‘float’>, expected ‘string’”, “LowerDetectionLimit”: “Validation failed(isDecimal): 0.0 of type <type ‘float’>, expected ‘string’”}”,
“success”: false
}

I think the failure is due to some datatype and not from the API itself?