Incorrect mimeType in Search

Olga Andreeva 126 Reputation points
2024-07-02T11:47:17.1966667+00:00

Hello,

I am using the following api:

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

{
    "requests": [
        {
            "entityTypes": [
                "driveItem"
            ],
            "query": {
                "queryString": "filename:fir.txt AND path:\"https://tenant-my.sharepoint.com/sites/xxx/Documents/folder\""
            },
			fields: [
                  'mimeType',
                  'id',
                  'parentReference',
                  'createdBy',
                  'name',
                  'createdDateTime',
                  'lastModifiedDateTime',
                ],
 }    

 ] 
} 

And I receive the following result in mimeType:

For file:

application/vnd.openxmlformats-officedocument.wordprocessingml.document\n\nDocument

For folder:

Folder

The result is confusing. Is it intended to be so?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,218 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,137 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,791 questions
{count} votes

Accepted answer
  1. Ling Zhou_MSFT 18,020 Reputation points Microsoft Vendor
    2024-07-04T08:37:43.81+00:00

    Hi @Olga Andreeva,

    Thank you for your reply. I checked the relevant information and got the following results:

    The additional string "\n\nDocument" in the mimeType property of the search result indicates that the file is a Word document.

    This is because the mimeType for Word documents is "application/vnd.openxmlformats-officedocument.wordprocessingml.document", and the "\n\nDocument" string is added to indicate that it is a document file.

    This behavior is expected and is not a cause for concern. But you may need to manually remove this value when using it.

    Please accept my sincerely apologize for any in convenience this may cause. Thank you for your kind understanding.


    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.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Michael Taylor 54,646 Reputation points
    2024-07-02T14:21:24.6866667+00:00

    Yes. The MIME type (which is what we generally refer to as the content type) tells the caller what format the data is being returned as. For an Office document it is returning the content type associated with Office documents. There is no such thing for folder so it can return whatever it wants.

    If you want to ensure it returns only types you support then use the Accept HTTP header and specify the format(s) you want. In general the server will attempt to return the format you requested. If it cannot find a match then most servers tend to just fail the call but that is up to the web server.

    0 comments No comments

  2. Olga Andreeva 126 Reputation points
    2024-07-04T07:27:35.4966667+00:00

    Hello @Michael Taylor and @Ling Zhou_MSFT ,

    Thank you for the attention to the question.

    Unfortunately, I cannot find it suitable for my case. The Accept header is a general feature of the HTTP server.I am asking about the particular Microsoft Graph API case - search endpoint:

    POST https://graph.microsoft.com/v1.0/search/query
    
    {
        "requests": [
            {
                "entityTypes": [
                    "driveItem"
                ],
                "query": {
                    "queryString": "filename:fir.txt AND path:\"https://tenant-my.sharepoint.com/sites/xxx/Documents/folder\""
                },
    			fields: [
                      'mimeType',
                      'id',
                      'parentReference',
                      'createdBy',
                      'name',
                      'createdDateTime',
                      'lastModifiedDateTime',
                    ],
     }    
    
     ] 
    } 
    
    

    And after I receive the result of this query in the response body (not response content-type header) I see that for the documents there is the mimeType:

    application/vnd.openxmlformats-officedocument.wordprocessingml.document\n\nDocument
    
    

    As you might see additional string is added: "\n\nDocument".

    For folders there is

    Folder
    
    

    Because of it I need to filter out the values "\n\nDocument" and "Folder" in my app to use mimeTypes efficiently.

    I do not see such problem in API like:

    /groups/{group-id}/drive/root/search(q='{search-text}')
    
    
    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.