REST API: integrating results from @vocabularies endpoint in custom dexterity content type

Hi all,

I am attempting to display some product category information from our internal Plone application on what will become a new public facing Plone site. plone.restapi allows me to easily search for the products to display on the new site by issuing a request like: http://intranet:8080/Plone/@search?product_categories=indoors

I have created a simple dexterity content type which contains a TextLine field where parameters can be endered to display pre-baked searches. The view then calls my query function and inserts the relevant metadata of resulting products on the page. My experience so far has been absolutely phenomenal, @tisto, @sneridagh and everybody else who contributed: you guys rock!

The next step would be to make the Textline field into a Choice field and get the option values from our intranet server using the @vocabularies endpoint.

 {
    "@id": "http://intranet:8080/Plone/@vocabularies/our_app.ProductCategories",
    "title": "our_app.ProductCategories"
  },

Something like: http://intranet:8080/Plone/@vocabularies/our_app.ProductCategories?b_size=50

Essentially, this will only be used when creating the actual categories.

How would I go about doing this, should I first create a local copy of the vocabulary or can I somehow directly insert the values from the remote server in my field?

Any hints are appreciated! - Norbert

With a local dynamic vocabulary, things seem to work. But it doesn't feel right...

@provider(IVocabularyFactory)
def ProductCategoriesVocabulary(object):
    """ return the ProductCategories vocabulary from our intranet
    """

    url = 'http://intranet:8080/Plone/@vocabularies/our_app.ProductCategories'

    target_language = 'de'
    query = {'b_size': 50}

    terms = get_rest_results(url=url, target_language=target_language, query=query).get('items', {})
    terms = [ SimpleTerm(value=term['token'], token=term['token'], title=term['title'])
            for term in terms]
    data = SimpleVocabulary(terms)

    return data

gets the results like this

def get_rest_results(url='', target_language='de', query={}):

   headers['Accept-Language'] = target_language
   headers['X-CSRF-TOKEN'] = createToken()

   payload = { 'Language' : target_language
             , 'metadata_fields' : '_all'
             , 'sort_on' : 'sortable_title'
             , }

   for key in query:
       payload[key] = query[key]

   results = requests.get(url, params=payload, headers=headers, auth=auth)

   json_results = results.json()

   return json_results

Victor and I are on holidays. Vocabularies and REST API are a complicated topic. I promise we get back on that in a few weeks...Other people that might be able to help in the meantime: @csenger @jaroel @buchi @lukasgraf