1

Create a ticket

by
Published Sep 3, 2022

Creates a ticket using the following endpoint: https://docs.zammad.org/en/latest/api/ticket/index.html#create

Script zammad
  • Submitted by jaller94 Deno
    Created 1233 days ago
    1
    export async function main(
    2
    	zammad_host: string,
    3
    	zammad_token: string,
    4
        user_agent?: string,
    5
        subject: string,
    6
        author_name: string,
    7
        author_email_address: string,
    8
        body: string,
    9
        content_type = "text/html",
    10
        type: "note" | "web" = "web",
    11
        internal = false,
    12
    ) {
    13
        // https://docs.zammad.org/en/latest/api/ticket/index.html#create
    14
    	const resp = await fetch(
    15
    		`${zammad_host}/api/v1/tickets`,
    16
    		{
    17
    			method: "POST",
    18
    			headers: {
    19
    				"Authorization": `Bearer ${zammad_token}`,
    20
                    "User-Agent": user_agent ?? "Public windmill.dev script",
    21
                },
    22
                body: JSON.stringify({
    23
                    title: subject || `Request from ${author_name} (${author_email_address})`,
    24
                    group,
    25
                    // This creates a new customer if the email address isn't in Zammad.
    26
                    customer_id: `guess:${author_email_address}`,
    27
                    article: {
    28
                        from: `${author_name} <${author_email_address}>`,
    29
                        type,
    30
                        subject,
    31
                        content_type,
    32
                        body,
    33
                        internal,
    34
                    },
    35
                    // Needed to make the API happy.
    36
                    fingerprint: crypto.randomUUID(),
    37
                }),
    38
    		},
    39
    	);
    40
    	if (!resp.ok) {
    41
    		throw Error(`Failed to create ticket: Error HTTP${resp.status}`);
    42
    	}
    43
        return await resp.json();
    44
    }