Edits history of script submission #3182 for ' Create an enum option (asana)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Asana = {
      token: string;
    };
    /**
     * Create an enum option
     * Creates an enum option and adds it to this custom field’s list of enum options. A custom field can have at most 500 enum options (including disabled options). By default new enum options are inserted at the end of a custom field’s list.
    Locked custom fields can only have enum options added by the user who locked the field.
    Returns the full record of the newly created enum option.
     */
    export async function main(
      auth: Asana,
      custom_field_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      limit: string | undefined,
      offset: string | undefined,
      body: {
        data?: ({ gid?: string; resource_type?: string; [k: string]: unknown } & {
          color?: string;
          enabled?: boolean;
          name?: string;
          [k: string]: unknown;
        }) & {
          insert_after?: string;
          insert_before?: string;
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://app.asana.com/api/1.0/custom_fields/${custom_field_gid}/enum_options`
      );
      for (const [k, v] of [
        ["opt_pretty", opt_pretty],
        ["opt_fields", opt_fields],
        ["limit", limit],
        ["offset", offset],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 383 days ago

  • nativets
    type Asana = {
      token: string;
    };
    /**
     * Create an enum option
     * Creates an enum option and adds it to this custom field’s list of enum options. A custom field can have at most 500 enum options (including disabled options). By default new enum options are inserted at the end of a custom field’s list.
    Locked custom fields can only have enum options added by the user who locked the field.
    Returns the full record of the newly created enum option.
     */
    export async function main(
      auth: Asana,
      custom_field_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      limit: string | undefined,
      offset: string | undefined,
      body: {
        data?: ({ gid?: string; resource_type?: string; [k: string]: unknown } & {
          color?: string;
          enabled?: boolean;
          name?: string;
          [k: string]: unknown;
        }) & {
          insert_after?: string;
          insert_before?: string;
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://app.asana.com/api/1.0/custom_fields/${custom_field_gid}/enum_options`
      );
      for (const [k, v] of [
        ["opt_pretty", opt_pretty],
        ["opt_fields", opt_fields],
        ["limit", limit],
        ["offset", offset],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 937 days ago