export async function main(
zammad_host: string,
zammad_token: string,
user_agent?: string,
firstname: string,
lastname: string,
email: string,
login?: string,
organisation?: string,
roles?: string[]
) {
const resp = await fetch(
`${zammad_host}/api/v1/users`,
{
method: "POST",
headers: {
"Authorization": `Bearer ${zammad_token}`,
"User-Agent": user_agent ?? "Public windmill.dev script",
},
body: JSON.stringify({
firstname,
lastname,
email,
...(login && {login}),
...(organisation && {organisation}),
...(roles && {roles}),
}),
},
);
if (!resp.ok && resp.status !== 422) {
throw Error(`Failed to create user: Error HTTP${resp.status}`);
}
return await resp.json();
}