Create a task
One script reply has been approved by the moderators Verified

Creates a new task.

At present, tasks can only be created from plaintext without record reference formatting.

Required scopes: task:read-write, object_configuration:read, record_permission:read, user_management:read.

Created by hugo697 51 days ago
Submitted by hugo697 Bun
Verified 51 days ago
1
//native
2
type Attio = {
3
  token: string;
4
};
5
/**
6
 * Create a task
7
 * Creates a new task.
8

9
At present, tasks can only be created from plaintext without record reference formatting.
10

11
Required scopes: `task:read-write`, `object_configuration:read`, `record_permission:read`, `user_management:read`.
12
 */
13
export async function main(
14
  auth: Attio,
15
  body: {
16
    data: {
17
      content: string;
18
      format: "plaintext";
19
      deadline_at: string;
20
      is_completed: false | true;
21
      linked_records:
22
        | { target_object: string; target_record_id: string }
23
        | {
24
            target_object: string;
25
            "[slug_or_id_of_matching_attribute]":
26
              | { domain?: string }
27
              | { email_address?: string }
28
              | { value?: number }
29
              | {
30
                  original_phone_number?: string;
31
                  country_code?:
32
                    | "AF"
33
                    | "AX"
34
                    | "AL"
35
                    | "DZ"
36
                    | "AS"
37
                    | "AD"
38
                    | "AO"
39
                    | "AI"
40
                    | "AQ"
41
                    | "AG"
42
                    | "AR"
43
                    | "AM"
44
                    | "AW"
45
                    | "AU"
46
                    | "AT"
47
                    | "AZ"
48
                    | "BS"
49
                    | "BH"
50
                    | "BD"
51
                    | "BB"
52
                    | "BY"
53
                    | "BE"
54
                    | "BZ"
55
                    | "BJ"
56
                    | "BM"
57
                    | "BT"
58
                    | "BO"
59
                    | "BA"
60
                    | "BW"
61
                    | "BV"
62
                    | "BR"
63
                    | "IO"
64
                    | "BN"
65
                    | "BG"
66
                    | "BF"
67
                    | "BI"
68
                    | "KH"
69
                    | "CM"
70
                    | "CA"
71
                    | "CV"
72
                    | "KY"
73
                    | "CF"
74
                    | "TD"
75
                    | "CL"
76
                    | "CN"
77
                    | "CX"
78
                    | "CC"
79
                    | "CO"
80
                    | "KM"
81
                    | "CG"
82
                    | "CD"
83
                    | "CK"
84
                    | "CR"
85
                    | "CI"
86
                    | "HR"
87
                    | "CU"
88
                    | "CW"
89
                    | "CY"
90
                    | "CZ"
91
                    | "DK"
92
                    | "DJ"
93
                    | "DM"
94
                    | "DO"
95
                    | "EC"
96
                    | "EG"
97
                    | "SV"
98
                    | "GQ"
99
                    | "ER"
100
                    | "EE"
101
                    | "ET"
102
                    | "FK"
103
                    | "FO"
104
                    | "FJ"
105
                    | "FI"
106
                    | "FR"
107
                    | "GF"
108
                    | "PF"
109
                    | "TF"
110
                    | "GA"
111
                    | "GM"
112
                    | "GE"
113
                    | "DE"
114
                    | "GH"
115
                    | "GI"
116
                    | "GR"
117
                    | "GL"
118
                    | "GD"
119
                    | "GP"
120
                    | "GU"
121
                    | "GT"
122
                    | "GG"
123
                    | "GN"
124
                    | "GW"
125
                    | "GY"
126
                    | "HT"
127
                    | "HM"
128
                    | "VA"
129
                    | "HN"
130
                    | "HK"
131
                    | "HU"
132
                    | "IS"
133
                    | "IN"
134
                    | "ID"
135
                    | "IR"
136
                    | "IQ"
137
                    | "IE"
138
                    | "IM"
139
                    | "IL"
140
                    | "IT"
141
                    | "JM"
142
                    | "JP"
143
                    | "JE"
144
                    | "JO"
145
                    | "KZ"
146
                    | "KE"
147
                    | "KI"
148
                    | "KR"
149
                    | "KW"
150
                    | "KG"
151
                    | "LA"
152
                    | "LV"
153
                    | "LB"
154
                    | "LS"
155
                    | "LR"
156
                    | "LY"
157
                    | "LI"
158
                    | "LT"
159
                    | "LU"
160
                    | "MO"
161
                    | "MK"
162
                    | "MG"
163
                    | "MW"
164
                    | "MY"
165
                    | "MV"
166
                    | "ML"
167
                    | "MT"
168
                    | "MH"
169
                    | "MQ"
170
                    | "MR"
171
                    | "MU"
172
                    | "YT"
173
                    | "MX"
174
                    | "FM"
175
                    | "MD"
176
                    | "MC"
177
                    | "MN"
178
                    | "ME"
179
                    | "MS"
180
                    | "MA"
181
                    | "MZ"
182
                    | "MM"
183
                    | "NA"
184
                    | "NR"
185
                    | "NP"
186
                    | "NL"
187
                    | "AN"
188
                    | "NC"
189
                    | "NZ"
190
                    | "NI"
191
                    | "NE"
192
                    | "NG"
193
                    | "NU"
194
                    | "NF"
195
                    | "MP"
196
                    | "NO"
197
                    | "OM"
198
                    | "PK"
199
                    | "PW"
200
                    | "PS"
201
                    | "PA"
202
                    | "PG"
203
                    | "PY"
204
                    | "PE"
205
                    | "PH"
206
                    | "PN"
207
                    | "PL"
208
                    | "PT"
209
                    | "PR"
210
                    | "QA"
211
                    | "RE"
212
                    | "RO"
213
                    | "RU"
214
                    | "RW"
215
                    | "BL"
216
                    | "SH"
217
                    | "KN"
218
                    | "LC"
219
                    | "MF"
220
                    | "PM"
221
                    | "VC"
222
                    | "WS"
223
                    | "SM"
224
                    | "ST"
225
                    | "SA"
226
                    | "SN"
227
                    | "SS"
228
                    | "RS"
229
                    | "SC"
230
                    | "SL"
231
                    | "SG"
232
                    | "SK"
233
                    | "SI"
234
                    | "SB"
235
                    | "SO"
236
                    | "ZA"
237
                    | "GS"
238
                    | "ES"
239
                    | "LK"
240
                    | "SD"
241
                    | "SR"
242
                    | "SJ"
243
                    | "SZ"
244
                    | "SE"
245
                    | "CH"
246
                    | "SY"
247
                    | "TW"
248
                    | "TJ"
249
                    | "TZ"
250
                    | "TH"
251
                    | "TL"
252
                    | "TG"
253
                    | "TK"
254
                    | "TO"
255
                    | "TT"
256
                    | "TN"
257
                    | "TR"
258
                    | "TM"
259
                    | "TC"
260
                    | "TV"
261
                    | "UG"
262
                    | "UA"
263
                    | "AE"
264
                    | "GB"
265
                    | "US"
266
                    | "UM"
267
                    | "UY"
268
                    | "UZ"
269
                    | "VU"
270
                    | "VE"
271
                    | "VN"
272
                    | "VG"
273
                    | "VI"
274
                    | "WF"
275
                    | "EH"
276
                    | "YE"
277
                    | "ZM"
278
                    | "ZW";
279
                }
280
              | { value?: string }[];
281
          }[];
282
      assignees:
283
        | {
284
            referenced_actor_type: "workspace-member";
285
            referenced_actor_id: string;
286
          }
287
        | { workspace_member_email_address: string }[];
288
    };
289
  },
290
) {
291
  const url = new URL(`https://api.attio.com/v2/tasks`);
292

293
  const response = await fetch(url, {
294
    method: "POST",
295
    headers: {
296
      "Content-Type": "application/json",
297
      Authorization: "Bearer " + auth.token,
298
    },
299
    body: JSON.stringify(body),
300
  });
301
  if (!response.ok) {
302
    const text = await response.text();
303
    throw new Error(`${response.status} ${text}`);
304
  }
305
  return await response.json();
306
}
307