Graph failure when using a hyphen (-) in a site name or a document library name in SharePoint Online

Cha, Inhwan (HPPK SW RnD) 0 Reputation points
2025-02-14T06:32:47.74+00:00

Title: Graph failure when using a hyphen (-) in a site name or a document library name in SharePoint Online

Description:

I encountered an error while verifying the following query in the Microsoft Graph Explorer:

Successful Query: When I send the following POST request, the query succeeds:

Query: https://graph.microsoft.com/v1.0/search/query

Request Body:
{
    "requests": [
        {
            "entityTypes": ["drive"],
            "query": {
                "queryString": "sites/test/HPPKTest AND Path:\"https://hpqdstest.sharepoint.com/sites/test/HPPKTest\""
            },
            "fields": ["id", "webUrl", "parentReference"]
        }
    ]
}

Response:
{
    "value": [
        {
            "searchTerms": ["sites/test/HPPKTest"],
            "hitsContainers": [
                {
                    "hits": [
                        {
                            "hitId": "b!QDQjd4N5ukawPHXlLOe9ToBj09zb69BIhCCkjiJ_GjzMPRWZRUuMTr5qwyASXXLx",
                            "rank": 1,
                            "summary": "",
                            "resource": {
                                "@odata.type": "#microsoft.graph.drive",
                                "id": "b!QDQjd4N5ukawPHXlLOe9ToBj09zb69BIhCCkjiJ_GjzMPRWZRUuMTr5qwyASXXLx",
                                "parentReference": {
                                    "sharepointIds": {
                                        "listId": "99153dcc-4b45-4e8c-be6a-c320125d72f1"
                                    },
                                    "siteId": "hpqdstest.sharepoint.com,77233440-7983-46ba-b03c-75e52ce7bd4e,dcd36380-ebdb-48d0-8420-a48e227f1a3c"
                                    },
                                "webUrl": "https://hpqdstest.sharepoint.com/sites/test/HPPKTest/Forms/AllItems.aspx"
                                }
                            }
                        ]
                    },
                    "total": 1,
                    "moreResultsAvailable": false
                }
            ]
        }
    ],
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}

Failed Query: When I send the following POST request, the query fails if the site or document library name contains a hyphen (-):

Query: https://graph.microsoft.com/v1.0/search/query

Request Body:
{
    "requests": [
        {
            "entityTypes": ["drive"],
            "query": {
                "queryString": "sites/test/HPPK-Test AND Path:\"https://hpqdstest.sharepoint.com/sites/test/HPPK-Test\""
            },
            "fields": ["id", "webUrl", "parentReference"]
        }
    ]
}

Response:
{
    "value": [
        {
            "searchTerms": ["sites/test/HPPK-Test"],
            "hitsContainers": [
                {
                    "total": 0,
                    "moreResultsAvailable": false
                }
            ]
        }
    ],
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}

It appears that the query fails specifically when a hyphen is included in the site or document library name.

Request: Could you please investigate this issue and provide a solution or workaround for using hyphens in site or document library names in SharePoint Online queries?

Thank you for your assistance.

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

1 answer

Sort by: Most helpful
  1. Rajat Vashistha-MSFT 680 Reputation points Microsoft Vendor
    2025-02-14T16:17:14.5933333+00:00

    Hi Cha, Inhwan (HPPK SW RnD),

    Thank you for reaching out to Microsoft!

    Upon reviewing the Microsoft Search API for searching OneDrive and SharePoint content (https://learn.microsoft.com/en-us/graph/search-concept-files), it has been determined that the search API does not support site-level search schemas. It operates at the tenant level.

    User's image

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.