1

How can I use the Microsoft Graph API from Postman to search for documents within all SharePoint sites in an organization based on a specific value in a custom column? I am currently not getting the expected results when making the request:

GET https://graph.microsoft.com/v1.0/search?$filter=listItem/all(d:d/fields/UniqueCustomID eq '081212')

The documents that have this custom column value are not being returned in the API response. What am I doing incorrectly?

cb0008
  • 93
  • 1
  • 8

2 Answers2

2

You need to send POST request to /search/query endpoint.

In the body specify the type of entities to be searched and in the query you can scope the query to only those with unique custom id.

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

{
  "requests": [
    {
      "entityTypes": [
        "listItem"
      ],
      "query": {
        "queryString": "UniqueCustomID=081212"
      }
    }
  ]
}

"queryString": "UniqueCustomID=081212": = has meaning equals

"queryString": "UniqueCustomID:081212": : has meaning contains

Documentation

Search content in SharePoint

user2250152
  • 14,658
  • 4
  • 33
  • 57
  • Thank you for your reply. When I try your example the result I get from the API starts with {"value":[{"searchTerms":["UniqueCustomID","081212"],... So it doesn't actually search the customcolumn values. The files I expect to get aren't listed, it just searches everything for the keywords 'UniqueCustomID' and '081212'. What am I doing wrong? – cb0008 Jan 18 '23 at 09:59
  • @cb0008 looks like that search API doesn't support filtering by custom field. – user2250152 Jan 18 '23 at 11:17
  • @cb0008 Is your custom column indexed? – user2250152 Jan 18 '23 at 11:47
  • The custom column wasn't indexed. But I just had it indexed just now by following the steps on https://learn.microsoft.com/en-us/sharepoint/dev/general-development/sharepoint-search-rest-api-overview . The result is still the same unfortunately. – cb0008 Jan 18 '23 at 12:10
  • If the API doesn't support the custom-column values, is there maybe a different way to do this, for example is the SharePoint Search REST API (not Microsoft Graph API) the way it should be done? – cb0008 Jan 18 '23 at 12:27
0

The final solution involved this:

cb0008
  • 93
  • 1
  • 8