//native
/**
* Delete User
* Delete a user. Okta requires the user to be DEPROVISIONED first: calling this on an active user deactivates it (first call) and a second call permanently deletes it. Set `send_email` to notify admins of the deactivation. This cannot be undone.
*/
export async function main(
auth: RT.Okta,
user_id: string,
send_email: boolean | undefined
) {
const url = new URL(
`${auth.org_url}/api/v1/users/${encodeURIComponent(user_id)}`
)
if (send_email !== undefined)
url.searchParams.append("sendEmail", String(send_email))
const response = await fetch(url, {
method: "DELETE",
headers: {
Authorization: `SSWS ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
if (response.status === 204) return { success: true }
return await response.json()
}
Submitted by hugo989 6 days ago