Edits history of script submission #22092 for ' Update group (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update group
     *
     */
    export async function main(
      auth: Zoho,
      group: string,
      body: {
        user_groups?: {
          created_by: { name: string; id: string };
          modified_by: { name: string; id: string };
          modified_time: string;
          created_time: string;
          description: string;
          id: string;
          name: string;
          sources_count: {
            territories: number;
            roles: number;
            groups: number;
            users: { inactive: number; deleted: number; active: number };
          };
          sources: {
            type: "territories" | "roles" | "users";
            source: { id: string; name: string };
            subordinates: false | true;
            sub_territories: false | true;
          }[];
        }[];
      },
    ) {
      const url = new URL(
        `https://zohoapis.com/crm/v8/settings/user_groups/${group}`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Zoho-oauthtoken " + 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