[Solved] Add Collection Criteria with plone.api

I just post this here since I used some time to figure out (the obvious)
Instead of trying to set the criteria on a collection more 'complicated', I found that it can easily be done with plone.api, even on 'create':

 my_collection = plone.api.content.create(
                type='Collection',
                container=portal,
                id='items-collection',
                title='My Items',
                layout='somelayout',
                query = [{'i': 'portal_type', 'o': 'plone.app.querystring.operation.selection.any', 'v': ['my_type']}]
            )

BTW: This can also be done via RESTAPI:

curl \
    -s -X POST ${SITE_URL} \
    -H "Accept: application/json" \
    -H "Content-Type: application/json" \
    --data-raw '{"@type":"Collection","title":"My Items","id";"'items-collection","query":[{"i": "portal_type","o":"plone.app.querystring.operation.selection.any","v":["my_type"]}]}' \
    --user ${USER}
1 Like