//native
export type DynSelect_group_id = string
// Dropdown of the org's groups so users pick a group instead of typing its opaque ID.
export async function group_id(auth: RT.Okta) {
const url = new URL(`${auth.org_url}/api/v1/groups`)
url.searchParams.append("limit", "200")
const response = await fetch(url, {
headers: {
Authorization: `SSWS ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const groups = (await response.json()) as {
id: string
profile: { name: string }
}[]
return groups.map((g) => ({
value: g.id,
label: g.profile?.name ? `${g.profile.name} (${g.id})` : g.id,
}))
}
/**
* List Group Members
* List the users that belong to a group. Page with `limit` and the `after` cursor from the previous response's Link header.
*/
export async function main(
auth: RT.Okta,
group_id: DynSelect_group_id,
limit: number | undefined,
after: string | undefined
) {
const url = new URL(`${auth.org_url}/api/v1/groups/${group_id}/users`)
if (limit !== undefined) url.searchParams.append("limit", String(limit))
if (after !== undefined && after !== "")
url.searchParams.append("after", after)
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: `SSWS ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 6 days ago