Edits history of script submission #23353 for ' Search People (outlook)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Search People
     * 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.
     */
    export async function main(
      auth: RT.Outlook,
      search: string | undefined,
      top: number = 10
    ) {
      const url = new URL("https://graph.microsoft.com/v1.0/me/people")
      url.searchParams.append("$top", String(top))
      if (search != null && search !== "") {
        url.searchParams.append("$search", `"${search.replace(/"/g, '\\"')}"`)
      }
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 6 hours ago

  • bunnative
    //native
    
    /**
     * Search People
     * 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 on the connection.
     */
    export async function main(
      auth: RT.Outlook,
      search: string | undefined,
      top: number = 10
    ) {
      const url = new URL("https://graph.microsoft.com/v1.0/me/people")
      url.searchParams.append("$top", String(top))
      if (search != null && search !== "") {
        url.searchParams.append("$search", `"${search.replace(/"/g, '\\"')}"`)
      }
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 6 hours ago