0

Search People

by
Published today

Search the people most relevant to the connected account (contacts, colleagues, recent correspondents) by name or email, ranked by relevance. Useful for resolving a name to an address before inviting or emailing. Requires People.Read, which is not a connection default: tick it when connecting.

Script outlook Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 hours ago
1
//native
2

3
/**
4
 * Search People
5
 * Search the people most relevant to the connected account (contacts, colleagues, recent correspondents) by name or email, ranked by relevance. Useful for resolving a name to an address before inviting or emailing. Requires People.Read, which is not a connection default: tick it when connecting.
6
 */
7
export async function main(
8
  auth: RT.Outlook,
9
  search: string | undefined,
10
  top: number = 10
11
) {
12
  const url = new URL("https://graph.microsoft.com/v1.0/me/people")
13
  url.searchParams.append("$top", String(top))
14
  if (search != null && search !== "") {
15
    url.searchParams.append("$search", `"${search.replace(/"/g, '\\"')}"`)
16
  }
17

18
  const response = await fetch(url, {
19
    headers: {
20
      Authorization: `Bearer ${auth.token}`,
21
      Accept: "application/json",
22
    },
23
  })
24

25
  if (!response.ok) {
26
    throw new Error(`${response.status} ${await response.text()}`)
27
  }
28

29
  return await response.json()
30
}
31