Edits history of script submission #3165 for ' Create a tag in a workspace (asana)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Asana = {
      token: string;
    };
    /**
     * Create a tag in a workspace
     * Creates a new tag in a workspace or organization.
    
    Every tag 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.
    
    Returns the full record of the newly created tag.
     */
    export async function main(
      auth: Asana,
      workspace_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      body: {
        data?: (({ gid?: string; resource_type?: string; [k: string]: unknown } & {
          name?: string;
          [k: string]: unknown;
        }) & {
          color?:
            | "dark-pink"
            | "dark-green"
            | "dark-blue"
            | "dark-red"
            | "dark-teal"
            | "dark-brown"
            | "dark-orange"
            | "dark-purple"
            | "dark-warm-gray"
            | "light-pink"
            | "light-green"
            | "light-blue"
            | "light-red"
            | "light-teal"
            | "light-brown"
            | "light-orange"
            | "light-purple"
            | "light-warm-gray";
          notes?: string;
          [k: string]: unknown;
        }) & {
          created_at?: string;
          followers?: ({
            gid?: string;
            resource_type?: string;
            [k: string]: unknown;
          } & { name?: string; [k: string]: unknown })[];
          permalink_url?: string;
          workspace?: {
            gid?: string;
            resource_type?: string;
            [k: string]: unknown;
          } & { name?: string; [k: string]: unknown };
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://app.asana.com/api/1.0/workspaces/${workspace_gid}/tags`
      );
      for (const [k, v] of [
        ["opt_pretty", opt_pretty],
        ["opt_fields", opt_fields],
      ]) {
        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 a tag in a workspace
     * Creates a new tag in a workspace or organization.
    
    Every tag 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.
    
    Returns the full record of the newly created tag.
     */
    export async function main(
      auth: Asana,
      workspace_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      body: {
        data?: (({ gid?: string; resource_type?: string; [k: string]: unknown } & {
          name?: string;
          [k: string]: unknown;
        }) & {
          color?:
            | "dark-pink"
            | "dark-green"
            | "dark-blue"
            | "dark-red"
            | "dark-teal"
            | "dark-brown"
            | "dark-orange"
            | "dark-purple"
            | "dark-warm-gray"
            | "light-pink"
            | "light-green"
            | "light-blue"
            | "light-red"
            | "light-teal"
            | "light-brown"
            | "light-orange"
            | "light-purple"
            | "light-warm-gray";
          notes?: string;
          [k: string]: unknown;
        }) & {
          created_at?: string;
          followers?: ({
            gid?: string;
            resource_type?: string;
            [k: string]: unknown;
          } & { name?: string; [k: string]: unknown })[];
          permalink_url?: string;
          workspace?: {
            gid?: string;
            resource_type?: string;
            [k: string]: unknown;
          } & { name?: string; [k: string]: unknown };
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://app.asana.com/api/1.0/workspaces/${workspace_gid}/tags`
      );
      for (const [k, v] of [
        ["opt_pretty", opt_pretty],
        ["opt_fields", opt_fields],
      ]) {
        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