Edits history of script submission #3240 for ' Add a user to a team (asana)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Asana = {
      token: string;
    };
    /**
     * Add a user to a team
     * The user making this call must be a member of the team in order to add others. The user being added must exist in the same organization as the team.
    
    Returns the complete team membership record for the newly added user.
     */
    export async function main(
      auth: Asana,
      team_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      body: { data?: { user?: string; [k: string]: unknown }; [k: string]: unknown }
    ) {
      const url = new URL(
        `https://app.asana.com/api/1.0/teams/${team_gid}/addUser`
      );
      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;
    };
    /**
     * Add a user to a team
     * The user making this call must be a member of the team in order to add others. The user being added must exist in the same organization as the team.
    
    Returns the complete team membership record for the newly added user.
     */
    export async function main(
      auth: Asana,
      team_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      body: { data?: { user?: string; [k: string]: unknown }; [k: string]: unknown }
    ) {
      const url = new URL(
        `https://app.asana.com/api/1.0/teams/${team_gid}/addUser`
      );
      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