Search... Ctrl + K

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

Created by jaller94 98 days ago Used 58 times 0 Points

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

No comments yet

Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
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();
}

Submitted by jaller94 98 days ago

Edited 71 days ago

No comments yet