0

I am unable to search using microsoft graph api. The documentation is here.

Below is the sample provided in documentation, which itself is not working. Can someone suggest please. I actually want to search for people (and as per documentation /search is recommended way over /people. with /people query I am getting issue as faced in another thread)

URL : https://graph.microsoft.com/v1.0/users/<my mailbox name>/search/query Request data:

    {
  "requests": [
    {
      "entityTypes": [
        "message"
      ],
      "query": {
        "queryString": "contoso"
      },
      "from": 0,
      "size": 25
    }
  ]
}

Response:

{
    "error": {
        "code": "Request_BadRequest",
        "message": "Unexpected segment DynamicPathSegment. Expected property/$value.",
        "innerError": {
            "date": "2023-01-18T16:19:05",
            "request-id": "29a310fe-b5cf-4ea1-a995-3a09941d6d13",
            "client-request-id": "29a310fe-b5cf-4ea1-a995-3a09941d6d13"
        }
    }
}
Sandeep Bhutani
  • 589
  • 7
  • 23

1 Answers1

0

Send the POST request to https://graph.microsoft.com/beta/search/query endpoint.

POST https://graph.microsoft.com/beta/search/query

Request body

{
    "requests": [
        {
            "entityTypes": [
                "person"
            ],
            "query": {
                "queryString": "Sandeep"
            },
            "from": 0,
            "size": 25
        }
    ]
}

Searching for people requires delegated permissions.

Searching only works for searching the signed-in user's relevant people, not for searching people relevant to other users.

user2250152
  • 14,658
  • 4
  • 33
  • 57
  • It needs a region.. When I specified region=NAM, I got error - "Application permission is only supported for the following entity types:site, list, listItem, drive and driveItem." – Sandeep Bhutani Jan 19 '23 at 07:59
  • @SandeepBhutani Yes, it was not clear if you are using delegated or application permissions. Searching with application permissions has a lot of limitations. One of them is that searching with application permissions doesn't support person entity – user2250152 Jan 19 '23 at 08:29
  • My application is replacement of outlook. so it is using graph api. Can I use delegated permissions in such scenario? Or is there any other alternative that how can I execute https://graph.microsoft.com/v1.0/users//search/query – Sandeep Bhutani Jan 19 '23 at 18:29
  • @SandeepBhutani If the application will be used per user and it's expected that user will have access only to his/her mails, then you need to use delegated permissions. Btw. there is no endpoint like graph.microsoft.com/v1.0/users//search/query – user2250152 Jan 20 '23 at 06:33
  • thanks for reply. So does it mean, that shared and generic mailboxes (like customer support mailboxes) will not work with delegated permissions? This is my scenario. – Sandeep Bhutani Jan 20 '23 at 11:39