//native
const graph = "https://graph.microsoft.com/v1.0"
export type DynSelect_site_id = string
export async function site_id(auth: RT.MsSharepoint) {
const response = await fetch(
`${graph}/sites?search=*&$select=id,displayName,webUrl&$top=200`,
{
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { value } = (await response.json()) as {
value: { id: string; displayName: string; webUrl: string }[]
}
return value.map((s) => ({
value: s.id,
label: `${s.displayName} (${s.webUrl})`,
}))
}
export type DynSelect_list_id = string
export async function list_id(auth: RT.MsSharepoint, site_id: string) {
const response = await fetch(
`${graph}/sites/${site_id}/lists?$select=id,displayName`,
{
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { value } = (await response.json()) as {
value: { id: string; displayName: string }[]
}
return value.map((l) => ({ value: l.id, label: l.displayName }))
}
/**
* Update List Item
* Update column values of a list item. `fields` maps column internal names to the new values; columns left out keep their value. Returns the item's full field set. Requires Sites.ReadWrite.All (a connection default).
*/
export async function main(
auth: RT.MsSharepoint,
site_id: DynSelect_site_id,
list_id: DynSelect_list_id,
item_id: string,
fields: { [key: string]: any }
) {
const response = await fetch(
`${graph}/sites/${site_id}/lists/${list_id}/items/${encodeURIComponent(item_id)}/fields`,
{
method: "PATCH",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(fields),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 5 hours ago