Edits history of script submission #22143 for ' Update user type (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update user type
     *
     */
    export async function main(
      auth: Zoho,
      portal: string,
      user_type_id: string,
      body: {
        user_type: {
          personality_module: {
            api_name: string;
            id: string;
            plural_label: string;
          };
          created_time: string;
          modified_time: string;
          modified_by: { name: string; id: string };
          created_by: { name: string; id: string };
          name: string;
          active: false | true;
          default: false | true;
          no_of_users: number;
          id: string;
          modules: {
            id: string;
            plural_label: string;
            shared_type: string;
            api_name: string;
            filters: { display_label: string; api_name: string; id: string }[];
            fields: { read_only: false | true; api_name: string; id: string }[];
            layouts: {
              display_label: string;
              name: string;
              id: string;
              _default_view: {
                display_label: string;
                name: string;
                id: string;
                type: string;
              };
            }[];
            views: {
              display_label: string;
              name: string;
              id: string;
              type: string;
            };
            permissions: {
              view: false | true;
              edit: false | true;
              edit_shared_records: false | true;
              create: false | true;
              delete: false | true;
              delete_attachment: false | true;
              create_attachment: false | true;
            };
          }[];
        }[];
      },
    ) {
      const url = new URL(
        `https://zohoapis.com/crm/v8/settings/portals/${portal}/user_type/${user_type_id}`,
      );
    
      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