Create a project

Create a new project in a workspace or team. Every project is required to be created in a specific workspace or organization, and this cannot be changed once set. Note that you can use the `workspace` parameter regardless of whether or not it is an organization. If the workspace for your project is an organization, you must also supply a `team` to share the project with. Returns the full record of the newly created project.

Script asana Verified

by hugo697 ยท 10/31/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Create a project
6
 * Create a new project in a workspace or team.
7

8
Every project is required to be created in a specific workspace or
9
organization, and this cannot be changed once set. Note that you can use
10
the `workspace` parameter regardless of whether or not it is an
11
organization.
12

13
If the workspace for your project is an organization, you must also
14
supply a `team` to share the project with.
15

16
Returns the full record of the newly created project.
17
 */
18
export async function main(
19
  auth: Asana,
20
  opt_pretty: string | undefined,
21
  opt_fields: string | undefined,
22
  body: {
23
    data?: (({ gid?: string; resource_type?: string; [k: string]: unknown } & {
24
      name?: string;
25
      [k: string]: unknown;
26
    }) & {
27
      archived?: boolean;
28
      color?:
29
        | "dark-pink"
30
        | "dark-green"
31
        | "dark-blue"
32
        | "dark-red"
33
        | "dark-teal"
34
        | "dark-brown"
35
        | "dark-orange"
36
        | "dark-purple"
37
        | "dark-warm-gray"
38
        | "light-pink"
39
        | "light-green"
40
        | "light-blue"
41
        | "light-red"
42
        | "light-teal"
43
        | "light-brown"
44
        | "light-orange"
45
        | "light-purple"
46
        | "light-warm-gray";
47
      created_at?: string;
48
      current_status?: (({
49
        gid?: string;
50
        resource_type?: string;
51
        [k: string]: unknown;
52
      } & { title?: string; [k: string]: unknown }) & {
53
        color: "green" | "yellow" | "red" | "blue";
54
        html_text?: string;
55
        text: string;
56
        [k: string]: unknown;
57
      }) & {
58
        author?: {
59
          gid?: string;
60
          resource_type?: string;
61
          [k: string]: unknown;
62
        } & { name?: string; [k: string]: unknown };
63
        created_at?: string;
64
        created_by?: {
65
          gid?: string;
66
          resource_type?: string;
67
          [k: string]: unknown;
68
        } & { name?: string; [k: string]: unknown };
69
        modified_at?: string;
70
        [k: string]: unknown;
71
      };
72
      current_status_update?: {
73
        gid?: string;
74
        resource_type?: string;
75
        [k: string]: unknown;
76
      } & {
77
        resource_subtype?:
78
          | "project_status_update"
79
          | "portfolio_status_update"
80
          | "goal_status_update";
81
        title?: string;
82
        [k: string]: unknown;
83
      };
84
      custom_field_settings?: (({
85
        gid?: string;
86
        resource_type?: string;
87
        [k: string]: unknown;
88
      } & { [k: string]: unknown }) & {
89
        custom_field?: ((({
90
          gid?: string;
91
          resource_type?: string;
92
          [k: string]: unknown;
93
        } & {
94
          date_value?: {
95
            date?: string;
96
            date_time?: string;
97
            [k: string]: unknown;
98
          };
99
          display_value?: string;
100
          enabled?: boolean;
101
          enum_options?: ({
102
            gid?: string;
103
            resource_type?: string;
104
            [k: string]: unknown;
105
          } & {
106
            color?: string;
107
            enabled?: boolean;
108
            name?: string;
109
            [k: string]: unknown;
110
          })[];
111
          enum_value?: ({
112
            gid?: string;
113
            resource_type?: string;
114
            [k: string]: unknown;
115
          } & {
116
            color?: string;
117
            enabled?: boolean;
118
            name?: string;
119
            [k: string]: unknown;
120
          }) & { [k: string]: unknown };
121
          multi_enum_values?: ({
122
            gid?: string;
123
            resource_type?: string;
124
            [k: string]: unknown;
125
          } & {
126
            color?: string;
127
            enabled?: boolean;
128
            name?: string;
129
            [k: string]: unknown;
130
          })[];
131
          name?: string;
132
          number_value?: number;
133
          resource_subtype?:
134
            | "text"
135
            | "enum"
136
            | "multi_enum"
137
            | "number"
138
            | "date"
139
            | "people";
140
          text_value?: string;
141
          type?: "text" | "enum" | "multi_enum" | "number";
142
          [k: string]: unknown;
143
        }) & {
144
          asana_created_field?:
145
            | "a_v_requirements"
146
            | "account_name"
147
            | "actionable"
148
            | "align_shipping_link"
149
            | "align_status"
150
            | "allotted_time"
151
            | "appointment"
152
            | "approval_stage"
153
            | "approved"
154
            | "article_series"
155
            | "board_committee"
156
            | "browser"
157
            | "campaign_audience"
158
            | "campaign_project_status"
159
            | "campaign_regions"
160
            | "channel_primary"
161
            | "client_topic_type"
162
            | "complete_by"
163
            | "contact"
164
            | "contact_email_address"
165
            | "content_channels"
166
            | "content_channels_needed"
167
            | "content_stage"
168
            | "content_type"
169
            | "contract"
170
            | "contract_status"
171
            | "cost"
172
            | "creation_stage"
173
            | "creative_channel"
174
            | "creative_needed"
175
            | "creative_needs"
176
            | "data_sensitivity"
177
            | "deal_size"
178
            | "delivery_appt"
179
            | "delivery_appt_date"
180
            | "department"
181
            | "department_responsible"
182
            | "design_request_needed"
183
            | "design_request_type"
184
            | "discussion_category"
185
            | "do_this_task"
186
            | "editorial_content_status"
187
            | "editorial_content_tag"
188
            | "editorial_content_type"
189
            | "effort"
190
            | "effort_level"
191
            | "est_completion_date"
192
            | "estimated_time"
193
            | "estimated_value"
194
            | "expected_cost"
195
            | "external_steps_needed"
196
            | "favorite_idea"
197
            | "feedback_type"
198
            | "financial"
199
            | "funding_amount"
200
            | "grant_application_process"
201
            | "hiring_candidate_status"
202
            | "idea_status"
203
            | "ids_link"
204
            | "ids_patient_link"
205
            | "implementation_stage"
206
            | "insurance"
207
            | "interview_area"
208
            | "interview_question_score"
209
            | "itero_scan_link"
210
            | "job_s_applied_to"
211
            | "lab"
212
            | "launch_status"
213
            | "lead_status"
214
            | "localization_language"
215
            | "localization_market_team"
216
            | "localization_status"
217
            | "meeting_minutes"
218
            | "meeting_needed"
219
            | "minutes"
220
            | "mrr"
221
            | "must_localize"
222
            | "name_of_foundation"
223
            | "need_to_follow_up"
224
            | "next_appointment"
225
            | "next_steps_sales"
226
            | "num_people"
227
            | "number_of_user_reports"
228
            | "office_location"
229
            | "onboarding_activity"
230
            | "owner"
231
            | "participants_needed"
232
            | "patient_date_of_birth"
233
            | "patient_email"
234
            | "patient_phone"
235
            | "patient_status"
236
            | "phone_number"
237
            | "planning_category"
238
            | "point_of_contact"
239
            | "position"
240
            | "post_format"
241
            | "prescription"
242
            | "priority"
243
            | "priority_level"
244
            | "product"
245
            | "product_stage"
246
            | "progress"
247
            | "project_size"
248
            | "project_status"
249
            | "proposed_budget"
250
            | "publish_status"
251
            | "reason_for_scan"
252
            | "referral"
253
            | "request_type"
254
            | "research_status"
255
            | "responsible_department"
256
            | "responsible_team"
257
            | "risk_assessment_status"
258
            | "room_name"
259
            | "sales_counterpart"
260
            | "sentiment"
261
            | "shipping_link"
262
            | "social_channels"
263
            | "stage"
264
            | "status"
265
            | "status_design"
266
            | "status_of_initiative"
267
            | "system_setup"
268
            | "task_progress"
269
            | "team"
270
            | "team_marketing"
271
            | "team_responsible"
272
            | "time_it_takes_to_complete_tasks"
273
            | "timeframe"
274
            | "treatment_type"
275
            | "type_work_requests_it"
276
            | "use_agency"
277
            | "user_name"
278
            | "vendor_category"
279
            | "vendor_type"
280
            | "word_count";
281
          currency_code?: string;
282
          custom_label?: string;
283
          custom_label_position?: "prefix" | "suffix";
284
          description?: string;
285
          enum_options?: ({
286
            gid?: string;
287
            resource_type?: string;
288
            [k: string]: unknown;
289
          } & {
290
            color?: string;
291
            enabled?: boolean;
292
            name?: string;
293
            [k: string]: unknown;
294
          })[];
295
          format?: "currency" | "identifier" | "percentage" | "custom" | "none";
296
          has_notifications_enabled?: boolean;
297
          is_global_to_workspace?: boolean;
298
          precision?: number;
299
          [k: string]: unknown;
300
        }) & {
301
          created_by?: {
302
            gid?: string;
303
            resource_type?: string;
304
            [k: string]: unknown;
305
          } & { name?: string; [k: string]: unknown };
306
          people_value?: ({
307
            gid?: string;
308
            resource_type?: string;
309
            [k: string]: unknown;
310
          } & { name?: string; [k: string]: unknown })[];
311
          [k: string]: unknown;
312
        }) & { [k: string]: unknown };
313
        is_important?: boolean;
314
        parent?: ({
315
          gid?: string;
316
          resource_type?: string;
317
          [k: string]: unknown;
318
        } & { name?: string; [k: string]: unknown }) & { [k: string]: unknown };
319
        project?: ({
320
          gid?: string;
321
          resource_type?: string;
322
          [k: string]: unknown;
323
        } & { name?: string; [k: string]: unknown }) & { [k: string]: unknown };
324
        [k: string]: unknown;
325
      })[];
326
      default_view?: "list" | "board" | "calendar" | "timeline";
327
      due_date?: string;
328
      due_on?: string;
329
      html_notes?: string;
330
      is_template?: boolean;
331
      members?: ({
332
        gid?: string;
333
        resource_type?: string;
334
        [k: string]: unknown;
335
      } & { name?: string; [k: string]: unknown })[];
336
      modified_at?: string;
337
      notes?: string;
338
      public?: boolean;
339
      start_on?: string;
340
      workspace?: ({
341
        gid?: string;
342
        resource_type?: string;
343
        [k: string]: unknown;
344
      } & { name?: string; [k: string]: unknown }) & { [k: string]: unknown };
345
      [k: string]: unknown;
346
    }) & {
347
      custom_fields?: { [k: string]: string };
348
      followers?: string;
349
      owner?: string;
350
      team?: string;
351
      [k: string]: unknown;
352
    };
353
    [k: string]: unknown;
354
  }
355
) {
356
  const url = new URL(`https://app.asana.com/api/1.0/projects`);
357
  for (const [k, v] of [
358
    ["opt_pretty", opt_pretty],
359
    ["opt_fields", opt_fields],
360
  ]) {
361
    if (v !== undefined && v !== "") {
362
      url.searchParams.append(k, v);
363
    }
364
  }
365
  const response = await fetch(url, {
366
    method: "POST",
367
    headers: {
368
      "Content-Type": "application/json",
369
      Authorization: "Bearer " + auth.token,
370
    },
371
    body: JSON.stringify(body),
372
  });
373
  if (!response.ok) {
374
    const text = await response.text();
375
    throw new Error(`${response.status} ${text}`);
376
  }
377
  return await response.json();
378
}
379