0

Get Site

by
Published today

Get a SharePoint site by id, or by address as `<hostname>:/<server-relative path>` (e.g. `contoso.sharepoint.com:/sites/Marketing`); `root` is the tenant's root site. A direct lookup, so it finds sites the search index does not have yet. Requires Sites.Read.All (covered by the default Sites.ReadWrite.All).

Script ms_sharepoint Verified

The script

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

3
const graph = "https://graph.microsoft.com/v1.0"
4

5
/**
6
 * Get Site
7
 * Get a SharePoint site by id, or by address as `<hostname>:/<server-relative path>` (e.g. `contoso.sharepoint.com:/sites/Marketing`); `root` is the tenant's root site. A direct lookup, so it finds sites the search index does not have yet. Requires Sites.Read.All (covered by the default Sites.ReadWrite.All).
8
 */
9
export async function main(
10
  auth: RT.MsSharepoint,
11

12
  site_id: string,
13
  select: string | undefined
14
) {
15
  const url = new URL(`${graph}/sites/${site_id}`)
16
  if (select != null && select !== "") {
17
    url.searchParams.append("$select", select)
18
  }
19

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

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

31
  return await response.json()
32
}
33