Only title and token in REST @vocabularies endpoint

Out of sheer curiosity, is there a reason that the @vocabularies endpoint does not provide the value?

{
    "@id": "http://localhost:8888/Plone/@vocabularies/plone.app.vocabularies.Catalog",
    "items": [
        {
            "title": "6741ad66b239429da1e3d0fe217c2beb",
            "token": "6741ad66b239429da1e3d0fe217c2beb"
        },
        {
            "title": "5077bc17ec424ac68cc8e7724706ca49",
            "token": "5077bc17ec424ac68cc8e7724706ca49"
        },
    ],
    "items_total": 2
}

Similar here: https://demo.plone.org/++api++/@vocabularies/plone.app.vocabularies.Catalog

Norbert via Plone Community wrote at 2023-6-30 10:57 +0000:

Out of sheer curiosity, is there a reason that the @vocabularies endpoint does not provide the value?

{
   "@id": "http://localhost:8888/Plone/@vocabularies/plone.app.vocabularies.Catalog",
   "items": [
       {
           "title": "6741ad66b239429da1e3d0fe217c2beb",
           "token": "6741ad66b239429da1e3d0fe217c2beb"
       },
       {
           "title": "5077bc17ec424ac68cc8e7724706ca49",
           "token": "5077bc17ec424ac68cc8e7724706ca49"
       },
   ],
   "items_total": 2
}

title represents the term towards a human user,
token towards a browser application.

You likely miss value: this is internal
(it contains the programmatic representation).

This depends on the createTerm implementation in plone.app.vocabularies.catalog. Your example creates a term which has UID set as title and token, but the value would be the brain. See plone.app.vocabularies/plone/app/vocabularies/catalog.py at master ยท plone/plone.app.vocabularies ยท GitHub ... unfortunately plone.restapi only returns title and token in the vocabulary serializer.

The docs have a little side note: Vocabularies and Sources โ€“ REST API โ€“ Endpoints โ€” Plone Documentation v6.0

Since the underlying value of a term might not necessarily be serializable (it could be an arbitrary Python object), plone.restapi only exposes and accepts tokens. It will transparently convert between tokens and values during serialization and deseralization. For this reason, the following endpoints only support tokenized vocabularies and sources, and they do not expose the terms' values.

1 Like

Thank you @dieter @petschki and @jaroel - another mystery (for me) uncovered :smile:

BTW, the documentation is fantastic, I hadn't seen it before. Will keep under my pillow.

1 Like