Issue
I am trying to get a list of all sites in Sharepoint using the Grapsh API to see if there is a specific site whose site name
starts with XXX.
But Graph API site search doesn't work as expected.
I performed a site search using https://graph.microsoft.com/v1.0/sites?search=*
, but each time I run the API, the number of sites that are hit by the search changes. (1st 85,744 sites, 2nd 85,778 sites, 3rd 85,777 sites )
# example
* Request URL : `https://graph.microsoft.com/v1.0/sites?search=*`
* Response Code : 200 (Since there is no error, the permission (Sites.Read.All) should have been granted.)
* Response Body (Resut is Paging)
{
"@odata.nextLink": "https://graph.microsoft.com/v1.0/sites?search=*&$skiptoken=s!xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"value":
{
"displayName": "DISPLAY_NAME_001",
"name": "XXX_001",
"webUrl": "https://host.sharepoint.com/sites/XXX_001",
"lastModifiedDateTime": "YYYY-MM-DDTHH:MM:SSZ",
"createdDateTime": "YYYY-MM-DDTHH:MM:SSZ",
"siteCollection": {
"hostname": "host.sharepoint.com"
},
"root": {},
"id": "host.sharepoint.com,a0000000-0000-0000-0000-000000000001,b0000000-0000-0000-0000-000000000001"
},
{
"displayName": "DISPLAY_NAME_002",
"name": "XXX_002",
"webUrl": "https://host.sharepoint.com/sites/XXX_002",
"lastModifiedDateTime": "YYYY-MM-DDTHH:MM:SSZ",
"createdDateTime": "YYYY-MM-DDTHH:MM:SSZ",
"siteCollection": {
"hostname": "host.sharepoint.com"
},
"root": {},
"id": "host.sharepoint.com,a0000000-0000-0000-0000-000000000002,b0000000-0000-0000-0000-000000000002"
}
],
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites"
}
・
・
・
* Last page
{
"value": [],
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites"
}
Also, when I specify a site ID in the seach={query}
when searching, there are cases where the search hits, and cases where the search does not hit, and the results differ depending on the target site.
# example
## hit case
* Request URL : `https://graph.microsoft.com/v1.0/sites?search=a0000000-0000-0000-0000-000000000001`
* Response Code : 200
* Response Body
{
"value":
{
"displayName": "DISPLAY_NAME_001",
"name": "XXX_001",
"webUrl": "https://host.sharepoint.com/sites/XXX_001",
"lastModifiedDateTime": "YYYY-MM-DDTHH:MM:SSZ",
"createdDateTime": "YYYY-MM-DDTHH:MM:SSZ",
"siteCollection": {
"hostname": "host.sharepoint.com"
},
"root": {},
"id": "host.sharepoint.com,a0000000-0000-0000-0000-000000000001,b0000000-0000-0000-0000-000000000001"
},
],
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites"
}
## no hit case
* Request URL : `https://graph.microsoft.com/v1.0/sites?search=a0000000-0000-0000-0000-000000000002`
* Response Code : 200
* Response Body
{
"value": [],
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites"
}
---
Question
I have two questions about this phenomenon.
1. Why do the search results change with each search? What does serach={query}
search for on a SharePoint site? And how "query" should be structured?
I don't understand the specification of the query because the documentation does not clearly explain what the search={query}
searches for and how the query is structured.
https://learn.microsoft.com/en-us/graph/api/site-search?view=graph-rest-1.0&tabs=http
2. Is there any way to search all sites in the Grapsh API other than search=*
?
According to this URL , it states
The `search=*` query may give you the results you're after but it is not guaranteed in all scenarios.
Graph API search may not support all site searches.
If the search=*
in the Grapsh API doesn't allow me to search all sites, is there any other way to get all sites?
---
I referred to the following sites but could not find a solution, so I asked the question.