How to retrieve Sharepoint site that contains special characters or numbers using Graph .NET SDK

Jakub Pernica 215 Reputation points
2023-06-02T06:25:55.4366667+00:00

I'm using the latest Microsoft Graph .NET SDK. Using delegated permissions, I try to retrieve a SharePoint site by it's display name. Let's say I have a sharepoint site with name "Some - site" or simply "Site2".

The way I'm approaching this problem in code is like this:

var response = await client.Sites.GetAsync((reqConfig) =>
{
	reqConfig.QueryParameters.Search = "Some - site";
    // reqConfig.QueryParameters.Search = "Site2";
});

The request fails with the Status Code 400: BadRequest with message:

"Syntax error: character '-' is not valid at position 5 in 'Some - site'."

Same goes for using numbers in Search ("Site2").

When I was using Application permissions, I was able to retrieve .GetAllSites() and loop through them to find a specific site. However, I'm now using on-behalf-of flow with Delegated permissions and can't retrieve all sites, that's why I'm using Search query.

What would be a solution for this problem?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,355 questions
0 comments No comments
{count} vote