Edits history of script submission #289 for ' Create a ticket (zammad)'

  • deno
    export async function main(
    	zammad_host: string,
    	zammad_token: string,
        user_agent?: string,
        subject: string,
        author_name: string,
        author_email_address: string,
        body: string,
        content_type = "text/html",
        type: "note" | "web" = "web",
        internal = false,
    ) {
        // https://docs.zammad.org/en/latest/api/ticket/index.html#create
    	const resp = await fetch(
    		`${zammad_host}/api/v1/tickets`,
    		{
    			method: "POST",
    			headers: {
    				"Authorization": `Bearer ${zammad_token}`,
                    "User-Agent": user_agent ?? "Public windmill.dev script",
                },
                body: JSON.stringify({
                    title: subject || `Request from ${author_name} (${author_email_address})`,
                    group,
                    // This creates a new customer if the email address isn't in Zammad.
                    customer_id: `guess:${author_email_address}`,
                    article: {
                        from: `${author_name} <${author_email_address}>`,
                        type,
                        subject,
                        content_type,
                        body,
                        internal,
                    },
                    // Needed to make the API happy.
                    fingerprint: crypto.randomUUID(),
                }),
    		},
    	);
    	if (!resp.ok) {
    		throw Error(`Failed to create ticket: Error HTTP${resp.status}`);
    	}
        return await resp.json();
    }

    Submitted by jaller94 1233 days ago