Edits history of script submission #20002 for ' Create Invites (segment)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Segment = {
      token: string;
      baseUrl: string;
    };
    /**
     * Create Invites
     * Invites a list of users to join a Workspace.
     */
    export async function main(
      auth: Segment,
      body: {
        invites: {
          email: string;
          permissions?: {
            roleId: string;
            resources?: {
              id: string;
              type: "FUNCTION" | "SOURCE" | "SPACE" | "WAREHOUSE" | "WORKSPACE";
            }[];
            labels?: { key: string; value: string; description?: string }[];
          }[];
        }[];
      },
    ) {
      const url = new URL(`${auth.baseUrl}/invites`);
    
      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 235 days ago