0

Create a project in a team

by
Published Oct 31, 2023

Creates a project shared with the given team. Returns the full record of the newly created project.

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