Edits history of script submission #22094 for ' Update holiday (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update holiday
     *
     */
    export async function main(
      auth: Zoho,
      holiday_id: string,
      body: {
        holidays?: {
          year: number;
          name: string;
          date: string;
          type: string;
          id: string;
          shift_hour: { name: string; id: string };
        }[];
      },
      X_CRM_ORG?: string,
    ) {
      const url = new URL(
        `https://zohoapis.com/crm/v8/settings/holidays/${holiday_id}`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        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