[SOLVED] restAPI search within found items

If I want to search for a folderish item with restAPI, and then search within that, what syntax do I use?

First search would be (something like):
'https://$url/@search?portal_type=MyFolderishType) (or maybe add &path&fullobjects=1 ?)

This gives me a list of items with @id, name, description, and if I use fullobject, also the UID. How do I search within those ?

Could the UID be used to search? Something like :

  https://theURL/@search?uid=theUID&portal_type=myContentType

What about a local search within the folderish item from your previous search?

https://theURL/path/of/the/content/item/from/previous/search/@search?portal_type=myContentType

From the docs:

Content in a Plone site can be searched for by invoking the /@search endpoint on any context:

GET /plone/@search HTTP/1.1 Accept: application/json

A search is contextual by default, i.e. it is bound to a specific context (a collection in HTTP REST terms) and searches within that collection and any sub-collections

Yes, but using the 'path' requires me to 'remove the domain name' from the string and then use this. Sounds like an extra operation that should not be needed since we have th UID (?) . plone.api can search within an item/UID, so I thought it was possible here too ? To me, it sounds like a very common task, so it is a bit strange if it is not possible

No, you use the @id property and append /search?...

If you want to go the more complicated way use the path query option: https://plonerestapi.readthedocs.io/en/latest/searching.html#query-options

No, plone.api.content.find() accepts a context to limit the search. You can get the context using plone.api.content.get() and then use this for your search. So the behavior is consistent between plone.api and plone.restapi.

Thanks. That is the part I did not find (or understand) in the docs.

So yes, my next search works by using

{id}/@search?portal_type=mytype

1 Like

Slightly off topic: I wonder if it is possible to find the modified date for a certain object. (then I will only search(list) if the folder or its content has been modified)

I assume I could do (but it feels a bit complicated for 'such a simple task')

 https://path/to/somewhere/@search?portal_type=Folder&fullobjects=1&depth=0&include_items=false

And then

 body = json.decode(myvariabe.body);
 modified = body['items']['modified']

(then I do a (new) search/listing if the modified date has changed (if not, my app will not update info)

All you need to do is include the modified field in the results :wink:

https://path/to/somewhere/@search?portal_type=Folder&metadata_fields=modified

Btw, you can perform date range searches using the REST-API as well (thanks to @MrTango for the hint):

https://path/to/somewhere/@search?metadata_fields=modified&modified.query:date=04-18-2021&modified.range=min&sort_on=modified&sort_order=descending

This will get you all items modified after 18th of April 2021.

So in your example your first query for the folderish content can already contain the modified query, then there is no need to parse and compare data in your app.

Super. Thanks

UPATE: I think I still has to 'filter', since the response is:

{@id: https://api.medialog.no/steder/@search?portal_type=Folder&metadata_fields=modified&depth=0&include_items=false&path.depth=0, items: [{@id: https://api.medialog.no/steder, @type: Folder, description: ,  modified: 2021-06-16T15:17:54+00:00, review_state: published, title: Steder}], items_total: 1}

Is there a list of all 'endpoints' (?) in Plone restAPI.

Would it be an idea to have one for some of the most common 'metadata',

maybe

 http://path/to/page/@modified 
 http://path/to/page/@publishing_state