5

I'm trying to get a list of items from Sitecore that match a custom tag field. This is from an external application so I need to use one of the APIs to do this.

I've tried using the Sitecore ItemService API like so:

https://{baseurl}/sitecore/api/ssc/item/search?Term=technology&fields=ItemName,ItemId,Tag&includeStandardTemplateFields=true

However it's not working as I'd hoped it would.

I also read this SSE post and I don't think all of the content in it is correct:

Use the ItemService to perform a content search - as the list of fields you send in the parameters are not the list of fields to search in but are instead the fields you want to return in the response.

This is documented here by Sitecore:

https://doc.sitecore.net/sitecore_experience_platform/developing/developing_with_sitecore/sitecoreservicesclient/the_restful_api_for_the_itemservice

So my question is how do I get a list of items which match a specific tag?

I've also tried using the Facet Option like so:

https://{baseurl}/sitecore/api/ssc/item/search?Term=technology&fields=ItemName,ItemId,Tag&includeStandardTemplateFields=true&facet=Tag|{61F954E0-0B1E-431D-B79F-2EDFF6CAD7B6}

The above doesn't work for me because:

  1. I'm forced to enter a 'Term' as this is mandatory, I don't want this as I just want to get any items matching Tags.
  2. The search does not march partial terms, so isn't very useful even if I could pass a search term
  3. I can't seem to limit the search to just search a single field (Tag)
  4. A further complexity is that their may be more than one tag (Item ID) stored against an item and I suspect that the facet filter will only look for full matches, not partial matches.

I would just use the Solr API to do a search, but I don't think I can as Lucene is being used instead of Solr to my knowledge.

Any thoughts on the above would be very welcome.

UPDATE:

I had some kind assistance from Vlad on slack and it's possible to pass * as a search term like so:

https://mysite.com/sitecore/api/ssc/item/search?term=*&facet=_templatename|Article&fields=ItemName,ItemId,TemplateName&includeStandardTemplateFields=true&database=master

It also looks like there are some inconsistencies in the way the field filter works and the facets. Facets have to be lowercase and also require the '_' prefix for standard fields, where as the &fields= list doesn't. I'm still not able to filter on my custom field though or multiple ids.

  • can you try with "term" to be lowercase ? – Vlad Iobagiu Mar 28 '18 at 12:57
  • Vlad I don't think case is the issue here, a standard term search works in lower and uppercase. I am aware Solr's api is case sensitive though. The issue here is more how a search via the API is structured and flexibility of it. – Adam Seabridge Mar 28 '18 at 13:00
1

I believe below 2 steps should work for you:

  1. Create an item with template "/sitecore/templates/System/Services/Item Service/Query/Query Definition", this has a Query and Database field, populate this accordingly
  2. Execute the query like this https://{base url}/sitecore/api/ssc/item/{id of item created in step 1}/query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.