Create user  (zammad)
One script reply has been approved by the moderators

0 points by jaller94 30 days ago | 21 uses

Creates a user in Zammad. This is most commonly a customer of yours.
Also succeeds, if the user already exists.

One script reply has been approved by the moderators
This version of script #155 was approved by the moderators as the one that fits the best the script ask: 'Create user'. It is safe to use in your flows in production.
0 points
by jaller94 30 days ago
edit by jaller94 4 days ago
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[]
) {
    // https://docs.zammad.org/en/latest/api/user.html#create
	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}),
            }),
		},
	);
    // HTTP 422 means that the user already exists.
	if (!resp.ok && resp.status !== 422) {
		throw Error(`Failed to create user: Error HTTP${resp.status}`);
	}
    return await resp.json();
}
edit/run in windmill raw embed