Edits history of script submission #21252 for ' Create shifts hours (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create shifts hours
     *
     */
    export async function main(
      auth: Zoho,
      body: {
        shift_hours?: {
          same_as_everyday: false | true;
          shift_days: string[];
          daily_timing: {}[];
          custom_timing: { days: string; shift_timing: {}[] }[];
          id: string;
          break_hours: {
            break_days: string[];
            same_as_everyday: false | true;
            daily_timing: {}[];
            custom_timing: { days: string; break_timing: {}[] }[];
            id: string;
          }[];
          users: {
            role: { name: string; id: string };
            name: string;
            id: string;
            email: string;
            zuid: string;
            effective_from: string;
          }[];
          holidays: { date: string; year: number; name: string; id: string }[];
          users_count: number;
          timezone: {};
          name: string;
        }[];
      },
      X_CRM_ORG?: string,
    ) {
      const url = new URL(
        `https://zohoapis.com/crm/v8/settings/business_hours/shift_hours`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          ...(X_CRM_ORG ? { "X-CRM-ORG": X_CRM_ORG } : {}),
          "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