1 | |
2 |
|
3 | |
4 | * Create ticket |
5 | * Open a SecureChange ticket in a workflow, filling the fields of its first step (e.g. a multi_access_request field for an access request). Returns the new ticket ID. |
6 | */ |
7 | export async function main( |
8 | auth: RT.TufinSecurechange, |
9 | workflow_name: string, |
10 | subject: string, |
11 | first_step_name: string, |
12 | fields: { [key: string]: any }[], |
13 | priority: "Critical" | "High" | "Normal" | "Low" | undefined |
14 | ) { |
15 | const base = auth.base_url.replace(/\/+$/, "") |
16 | const url = new URL(`${base}/securechangeworkflow/api/securechange/tickets`) |
17 |
|
18 | const body = { |
19 | ticket: { |
20 | subject, |
21 | priority: priority || "Normal", |
22 | workflow: { name: workflow_name }, |
23 | steps: { |
24 | step: [ |
25 | { |
26 | name: first_step_name, |
27 | tasks: { task: { fields: { field: fields } } }, |
28 | }, |
29 | ], |
30 | }, |
31 | }, |
32 | } |
33 |
|
34 | const response = await fetch(url, { |
35 | method: "POST", |
36 | headers: { |
37 | Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`, |
38 | "Content-Type": "application/json", |
39 | Accept: "application/json", |
40 | }, |
41 | body: JSON.stringify(body), |
42 | }) |
43 |
|
44 | if (!response.ok) { |
45 | throw new Error(`${response.status} ${await response.text()}`) |
46 | } |
47 |
|
48 | |
49 | const location = response.headers.get("Location") ?? "" |
50 | const id = location.split("/").filter(Boolean).pop() |
51 | return { id: id ? Number(id) : null, location } |
52 | } |
53 |
|