Edits history of script submission #21165 for ' Clone profiles (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Clone profiles
     *
     */
    export async function main(
      auth: Zoho,
      id: string,
      body: {
        profiles: {
          _default_view?: { name?: string; id?: string; type?: string };
          name: string;
          description: string;
          id: string;
          default?: false | true;
          _delete?: false | true;
          permission_type?: string;
          custom?: false | true;
          display_label: string;
          type?: "normal_profile" | "lite_profile";
          permissions_details: {
            id: string;
            enabled: false | true;
            name: string;
            display_label: string;
            customizable?: false | true;
            parent_permissions?: string[];
            module: string;
          }[];
          sections: {
            name: string;
            categories:
              | {
                  display_label: string;
                  permissions_details: string[];
                  name: string;
                }
              | {
                  display_label: string;
                  permissions_details: string[];
                  name: string;
                  module: string;
                }[];
          }[];
          created_time: string;
          modified_time: string;
          modified_by: { name: string; id: string; email?: string };
          category: false | true;
          created_by: { name: string; id: string; email?: string };
        }[];
      },
    ) {
      const url = new URL(
        `https://zohoapis.com/crm/v8/settings/profiles/${id}/actions/clone`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        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