0

Update a workflow based on the ID

by
Published Oct 17, 2025

Updates a workflow based on the Workflow ID.

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Update a workflow based on the ID
7
 * Updates a workflow based on the Workflow ID.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  id: string,
12
  body: {
13
    name?: string;
14
    replaces?: string;
15
    description?: string;
16
    meta?: {};
17
    trigger?:
18
      | {
19
          id: string;
20
          eventName?: string;
21
          callable: false | true;
22
          schema: {};
23
          meta?: {};
24
          transitions: {
25
            meta?: {};
26
            target: string;
27
            condition: {
28
              op:
29
                | "and"
30
                | "or"
31
                | "exists"
32
                | "dne"
33
                | "true"
34
                | "false"
35
                | "eq"
36
                | "neq"
37
                | "gt"
38
                | "gte"
39
                | "lt"
40
                | "lte"
41
                | "lt-date"
42
                | "gt-date"
43
                | "contains"
44
                | "not-contains";
45
              values: unknown[];
46
            };
47
          }[];
48
        }
49
      | {
50
          id: string;
51
          appVersion?: string;
52
          meta?: {};
53
          eventName: string;
54
          transitions: {
55
            meta?: {};
56
            target: string;
57
            condition: {
58
              op:
59
                | "and"
60
                | "or"
61
                | "exists"
62
                | "dne"
63
                | "true"
64
                | "false"
65
                | "eq"
66
                | "neq"
67
                | "gt"
68
                | "gte"
69
                | "lt"
70
                | "lte"
71
                | "lt-date"
72
                | "gt-date"
73
                | "contains"
74
                | "not-contains";
75
              values: unknown[];
76
            };
77
          }[];
78
        };
79
    steps?: {
80
      id: string;
81
      appVersion?: string;
82
      meta?: {};
83
      action?: string;
84
      params?: {};
85
      transitions: {
86
        meta?: {};
87
        target: string;
88
        condition: {
89
          op:
90
            | "and"
91
            | "or"
92
            | "exists"
93
            | "dne"
94
            | "true"
95
            | "false"
96
            | "eq"
97
            | "neq"
98
            | "gt"
99
            | "gte"
100
            | "lt"
101
            | "lte"
102
            | "lt-date"
103
            | "gt-date"
104
            | "contains"
105
            | "not-contains";
106
          values: unknown[];
107
        };
108
      }[];
109
      errorCases?: {
110
        condition: { op: "and" | "or"; values: unknown[] };
111
        errorAction: {
112
          type?:
113
            | "continue"
114
            | "retry-workflow"
115
            | "retry-action"
116
            | "stop-processing";
117
        };
118
      }[];
119
    }[];
120
    enabled?: false | true;
121
    logging?: false | true;
122
  },
123
) {
124
  const url = new URL(`https://api.kustomerapp.com/v1/workflows/${id}`);
125

126
  const response = await fetch(url, {
127
    method: "PUT",
128
    headers: {
129
      "Content-Type": "application/json",
130
      Authorization: "Bearer " + auth.apiKey,
131
    },
132
    body: JSON.stringify(body),
133
  });
134
  if (!response.ok) {
135
    const text = await response.text();
136
    throw new Error(`${response.status} ${text}`);
137
  }
138
  return await response.json();
139
}
140