3

quick background, got a standalone app (.exe) which imports "products" into a Sitecore site and basically i need to do a content search for a field on the external product e.g. productId (saved on the sitecore item equavalent of that products, so i can work out if that product exists or i need to create a new one.

So far, the best way i have is to get the children from sitecore products parent and loop through them to check using e.g. http://{host}/sitecore/api/ssc/item/{guid}/children?database=master but as you can image with a lot of products this is going to take ages.

Ideally i want to do something like http://{host}/sitecore/api/ssc/item/?searchterm=productId&database=master, so that i can pass the term to search , in this case the productid, and get either 1 item back or null.

I have seen a few examples using the old web API with something like query:fast wonder if there is something similar in the new API.

Please can you provide some examples to try, keep in mind am still new to sitecore as well so treat me like i dont know anything at all :).

0
4

You can run a Sitecore search right from the REST Api:

The url would be:

http://{host}/sitecore/api/ssc/item/?term&pageSize&page&database&language&includeStandardTemplateFields&fields&sorting&facet

For you the relevant query string variables would be:

  • term: this is the text to search for - the field that it searches can be defined.
  • database: self-explanatory
  • fields: A comma separated list of fields you want to search

So as an example you might have:

http://{host}/sitecore/api/ssc/item/?term=12345&database=master&fields=ProductId

The full documentation for running a Sitecore Search is here: https://doc.sitecore.net/sitecore_experience_platform/developing/developing_with_sitecore/sitecoreservicesclient/the_restful_api_for_the_itemservice#_Toc395865048

2
  • Thanks saw that documentation (downloaded a pdf of that as well) and thats the one i been going off so far until the search. I must be missing something then because when i run my search (using the advanced REST Client) i get a 404 message. My url is this ssd.tac.cloud/sitecore/api/ssc/item/… and in the response back i get this message "The item "No Item with Path = " was not found. It may have been deleted by another user." like its looking for something to do the search with. – denford mutseriwa Aug 22 '17 at 22:38
  • @denfordmutseriwa I don't think the info above regarding fields is correct, from my testing and according to documentation it is: fields - Specify the names of the fields to retrieve in a comma-separated list – Adam Seabridge Mar 28 '18 at 13:01
1

So after a few painful tries and experiments, discovered that what is missing in all the API examples i can see is the most important and obvious word "Search" so the URL Should be

http://{host}/sitecore/api/ssc/item/search?term=12345&database=master&fields=ProductId

Also a few more pointers , i think for custom fields you will need an index set with those fields otherwise it will only search the standard sitecore fields. As for the standard field like ItemName can only do a full term search e.g. cant do a partial search for the term "the" in "climbing the roof" it would have to be the full term "climbing the roof".

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.