0

Create user

by
Published Sep 3, 2022

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

Script zammad Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 6 days ago
1
//native
2

3
export async function main(
4
  zammad_host: string,
5
  zammad_token: string,
6
  user_agent?: string,
7
  firstname: string,
8
  lastname: string,
9
  email: string,
10
  login?: string,
11
  organisation?: string,
12
  roles?: string[],
13
) {
14
  // https://docs.zammad.org/en/latest/api/user.html#create
15
  const resp = await fetch(`${zammad_host}/api/v1/users`, {
16
    method: "POST",
17
    headers: {
18
      Authorization: `Bearer ${zammad_token}`,
19
      "User-Agent": user_agent ?? "Public windmill.dev script",
20
    },
21
    body: JSON.stringify({
22
      firstname,
23
      lastname,
24
      email,
25
      ...(login && { login }),
26
      ...(organisation && { organisation }),
27
      ...(roles && { roles }),
28
    }),
29
  });
30
  // HTTP 422 means that the user already exists.
31
  if (!resp.ok && resp.status !== 422) {
32
    throw Error(`Failed to create user: Error HTTP${resp.status}`);
33
  }
34
  return await resp.json();
35
}
36

Other submissions
  • Submitted by jaller94 Deno
    Created 398 days ago
    1
    export async function main(
    2
      zammad_host: string,
    3
      zammad_token: string,
    4
      user_agent?: string,
    5
      firstname: string,
    6
      lastname: string,
    7
      email: string,
    8
      login?: string,
    9
      organisation?: string,
    10
      roles?: string[],
    11
    ) {
    12
      // https://docs.zammad.org/en/latest/api/user.html#create
    13
      const resp = await fetch(`${zammad_host}/api/v1/users`, {
    14
        method: "POST",
    15
        headers: {
    16
          Authorization: `Bearer ${zammad_token}`,
    17
          "User-Agent": user_agent ?? "Public windmill.dev script",
    18
        },
    19
        body: JSON.stringify({
    20
          firstname,
    21
          lastname,
    22
          email,
    23
          ...(login && { login }),
    24
          ...(organisation && { organisation }),
    25
          ...(roles && { roles }),
    26
        }),
    27
      });
    28
      // HTTP 422 means that the user already exists.
    29
      if (!resp.ok && resp.status !== 422) {
    30
        throw Error(`Failed to create user: Error HTTP${resp.status}`);
    31
      }
    32
      return await resp.json();
    33
    }
    34