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
}