Microsoft.Office.Server.Search.REST.SearchServiceException error when using SharePoint Search API

Jasper Chang 0 Reputation points
2024-05-08T03:56:01.8733333+00:00

I received error when I sent search sharepoint api.

api url:

https://johnscoca.sharepoint.com/_api/Search/Query?QueryText='contentclass:STS_Site contentclass:STS_Web NOT IsExternalContent:true'&SourceId='8413cd39-2156-4e00-b54d-11efd9abdb89'&EnableQueryRules=false&EnableStemming=false&TrimDuplicates=false&StartRow=0&RowLimit=50&SelectProperties='Title,Path,Description,contentclass,WebTemplate,LastModifiedTime'

document:

https://learn.microsoft.com/en-us/sharepoint/dev/general-development/sharepoint-search-rest-api-overview

api response:

<?xml version="1.0" encoding="utf-8"?>

<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

<m:code>-1, Microsoft.Office.Server.Search.REST.SearchServiceException</m:code>

<m:message xml:lang="en-US">We didn't understand your search terms. Make sure they're using proper syntax.</m:message>

</m:error>

sharepoint search api It has been found that removing the QueryText from the param or passing an empty string allows the API to succeed.

Then, I tried to send graph api (search sharepoint api), getting error "generalException"
api url:
https://graph.microsoft.com/v1.0/sites?search=*&$top=1000

document:
https://learn.microsoft.com/en-us/graph/api/site-search?view=graph-rest-1.0&tabs=http

api response:
{

"error": {

    "code": "generalException",

    "message": "General exception while processing",

    "innerError": {

        "date": "2024-05-07T06:49:10",

        "request-id": "9b1286dc-bd8f-4650-9557-d21f6734237c",

        "client-request-id": "9b1286dc-bd8f-4650-9557-d21f6734237c"

    }

}

}
graph search api

What is the reason and how can it be resolved? Thanks.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,913 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 32,401 Reputation points Microsoft Vendor
    2024-05-08T06:53:23.6933333+00:00

    Hi @Jasper Chang,

    Try using SharePoint search REST API endpoint like below

    https://xxx.sharepoint.com/_api/search/query?querytext='SPContentType:"Site Page" AND IsDocument:True AND FileExtension:aspx AND PromotedState:2 AND RefinableString05:true AND (Path:https://xxx.sharepoint.com/sites/site1 OR Path:https://xxx.sharepoint.com/sites/site2/SitePages OR Path:https://xxx.sharepoint.com/sites/site3 AND RefinableString01:"fieldvalue")'&sortlist etc
    
    
    

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

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.