//native
const graph = "https://graph.microsoft.com/v1.0"
/**
* Search Sites
* Search the SharePoint sites the connected account can reach by name or description; an empty `search` lists them all. Results come from the search index, so a site created minutes ago may be missing: use Get Site for those. Pass the returned `@odata.nextLink` as `next_link` for the next page. Requires Sites.Read.All (covered by the default Sites.ReadWrite.All).
*/
export async function main(
auth: RT.MsSharepoint,
search: string | undefined,
select: string | undefined,
top: number = 100,
next_link: string | undefined
) {
if (
next_link != null &&
next_link !== "" &&
!next_link.startsWith("https://graph.microsoft.com/")
) {
throw new Error(
"next_link must be an @odata.nextLink returned by Microsoft Graph"
)
}
let url: URL
if (next_link != null && next_link !== "") {
url = new URL(next_link)
} else {
url = new URL(`${graph}/sites`)
url.searchParams.append("$top", String(top))
url.searchParams.append(
"search",
search != null && search !== "" ? search : "*"
)
if (select != null && select !== "") {
url.searchParams.append("$select", select)
}
}
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 5 hours ago