1 | |
2 | type Smartsheet = { |
3 | token: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * Update an Automation Rule |
8 | * Updates an existing automation rule. |
9 |
|
10 | When sending an AutomationRule, you must always specify **action.type** and it must match the existing rule type. |
11 |
|
12 | */ |
13 | export async function main( |
14 | auth: Smartsheet, |
15 | sheetId: string, |
16 | automationRuleId: string, |
17 | body: { |
18 | id?: number; |
19 | action?: {}; |
20 | createdAt?: string | number; |
21 | createdBy?: { email?: string; name?: string }; |
22 | disabledReason?: |
23 | | "APPROVAL_COLUMN_MISSING" |
24 | | "APPROVAL_COLUMN_WRONG_TYPE" |
25 | | "AUTOMATION_NOT_ENABLED_FOR_ORG" |
26 | | "COLUMN_MISSING" |
27 | | "COLUMN_TYPE_INCOMPATIBLE" |
28 | | "NO_POTENTIAL_RECIPIENTS" |
29 | | "NO_VALID_SELECTED_COLUMNS"; |
30 | disabledReasonText?: string; |
31 | enabled?: false | true; |
32 | modifiedAt?: string | number; |
33 | modifiedBy?: { email?: string; name?: string }; |
34 | name?: string; |
35 | userCanModify?: false | true; |
36 | }, |
37 | ) { |
38 | const url = new URL( |
39 | `${auth.baseUrl}/sheets/${sheetId}/automationrules/${automationRuleId}`, |
40 | ); |
41 |
|
42 | const response = await fetch(url, { |
43 | method: "PUT", |
44 | headers: { |
45 | "Content-Type": "application/json", |
46 | Authorization: "Bearer " + auth.token, |
47 | }, |
48 | body: JSON.stringify(body), |
49 | }); |
50 | if (!response.ok) { |
51 | const text = await response.text(); |
52 | throw new Error(`${response.status} ${text}`); |
53 | } |
54 | return await response.json(); |
55 | } |
56 |
|