Forum Discussion
_api/search/query doesn't seems to consider sourceid, siteid or webid or path querystring params
Hi Friends,
I am using SharePoint Online and I have 2 site collections. I am using the Search REST API and I would like to search only in one site collection. But the search is performed at tenant level always, though the sourceId or SiteId or WebId GUID or Path values are provided in the API request.
Site Collections
https://xxxx.SharePoint.com/sites/SC1
https://xxxx.SharePoint.com/sites/SC2
Search REST API query
I have tried below queries and all results returned data from SC2 as well.
- _api/search/query?querytext='1234'&siteId='[GUID of SC1]'
- _api/search/query?querytext='1234'&sourceId='[GUID of SC1]'
- _api/search/query?querytext='1234'&webId='[GUID of SC1]'
- _api/search/query?querytext='1234'&path='https://xxxx.SharePoint.com/sites/SC1'
I am sending the query using Power Automate Flow.
Looking for help for fix.
Thanks
Anjan
please try something like this
https://contoso.sharepoint.com/_api/search/query?querytext='test path:https://contoso.sharepoint.com/sites/SiteTest'
Path or other parameters should be included in one querytext.
In more complex cases, you can try a POST query -> https://learn.microsoft.com/en-us/sharepoint/dev/general-development/sharepoint-search-rest-api-overview#post-requests
- michalkornetIron Contributor
please try something like this
https://contoso.sharepoint.com/_api/search/query?querytext='test path:https://contoso.sharepoint.com/sites/SiteTest'
Path or other parameters should be included in one querytext.
In more complex cases, you can try a POST query -> https://learn.microsoft.com/en-us/sharepoint/dev/general-development/sharepoint-search-rest-api-overview#post-requests
- Anjan_ChidigeCopper ContributorThanks Michalkornet. It worked. 🙂