I am trying to get the DataLocationCode
value of any site.
I have tried various syntaxes on Graph Explorer(see below). I am new to building my own query strings, I normally use simple calls via the C# SDK instead. Whilst I do need to obtain this DataLocationCode
so that I can use the Search
endpoint, I am also using this problem as an excuse to better understand OData query string for Ms Graph.
Simple call
https://graph.microsoft.com/v1.0/sites/{siteid}
returns
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites/$entity",
"@microsoft.graph.tips": "Use $select to choose only the properties your app needs, as this can lead to performance improvements. For example: GET sites('<key>')?$select=displayName,error",
"createdDateTime": "2023-08-10T15:14:45.583Z",
"description": "a_description",
"id": "tenant.sharepoint.com,some_guid,some_guid",
"lastModifiedDateTime": "2023-08-20T12:10:08Z",
"name": "P008-Baltik",
"webUrl": "https://tenantname.sharepoint.com/sites/some_name",
"displayName": "some site name",
"root": {},
"siteCollection": {
"hostname": "tenantname.sharepoint.com"
}
}
$select call
https://graph.microsoft.com/v1.0/sites/{siteid}?$select=siteCollection
returns
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites(siteCollection)/$entity",
"siteCollection": {
"hostname": "tenant.sharepoint.com"
}
}
Nested $select call (tentative)
https://graph.microsoft.com/v1.0/sites/{siteid}?$select=siteCollection/dataLocationCode
returns
{
"error": {
"code": "BadRequest",
"message": "Select options are not supported.",
"innerError": {
"date": "2023-08-28T14:58:15",
"request-id": "some_guid",
"client-request-id": "some_guid"
}
}
}
$expand call
https://graph.microsoft.com/v1.0/sites/{siteid}?$expand=siteCollection&select=dataLocationCode
returns
{
"error": {
"code": "BadRequest",
"message": "Parsing OData Select and Expand failed: Property 'siteCollection' on type 'microsoft.graph.site' is not a navigation property or complex property. Only navigation properties can be expanded.",
"innerError": {
"date": "2023-08-28T15:18:10",
"request-id": "some_guid",
"client-request-id": "some_guid"
}
}
}
You can call the /Search
endpoint with a random region
code (for example US
or ABC
). The endpoint will return an OData error which includes the possible region codes, for example:
Requested region not found. Only valid regions are EMEA.
The table with all possible codes is available here: https://learn.microsoft.com/en-us/microsoft-365/enterprise/microsoft-365-multi-geo?view=o365-worldwide
Note this table does not include EMEA
, which is a valid code in my case.