Question:

Relative item path in layout service call is not working

Mia: 5 days ago

I am trying to access Sitecore 10.1 item via layout services and it is working fine with GUID and full path. But when I am trying to access it via a relative path from the current app, it is not working. like https://cm.myproject.localhost/sitecore/api/layout/render/jss?sc_site=MyProject&sc_apikey=06d43b65-6732-46b2-becd-ce047675df71&item=/CustomHome&sc_lang=en.

However, it is working fine with this full item path like https://cm.myproject.localhost/sitecore/api/layout/render/jss?sc_site=MyProject&sc_apikey=06d43b65-6732-46b2-becd-ce047675df71&item=/sitecore/content/MyProject/CustomHome&sc_lang=en

Answer:
Kennedy: 5 days ago

We have discussed the issue in a private chat and figured out, that the /CustomHome item are placed on the same level with a site start item which makes it impossible to resolved by relative path. In general, Layout Service item resolving process looks similar with an original item resolving: 1) Sitecore sites are resolved based on hostname or sc_site query string; 2) start item path (which is usually home page) is calculated based on the site configuration: siteRoot + startItem 3) the requested item is resolved based on the start item path + value from the item query string. If requested item is not under the site start item, it will be impossible to get it by relative path.