Creates a Payroll Calendar

Script xero Verified

by hugo697 ยท 12/20/2024

The script

Submitted by hugo697 Bun
Verified 515 days ago
1
//native
2
type Xero = {
3
  token: string;
4
};
5
/**
6
 * Creates a Payroll Calendar
7
 *
8
 */
9
export async function main(
10
  auth: Xero,
11
  Xero_Tenant_Id: string,
12
  Idempotency_Key: string,
13
  body: {
14
    Name?: string;
15
    CalendarType?:
16
      | "WEEKLY"
17
      | "FORTNIGHTLY"
18
      | "FOURWEEKLY"
19
      | "MONTHLY"
20
      | "TWICEMONTHLY"
21
      | "QUARTERLY";
22
    StartDate?: string;
23
    PaymentDate?: string;
24
    PayrollCalendarID?: string;
25
    UpdatedDateUTC?: string;
26
    ReferenceDate?: string;
27
    ValidationErrors?: { Message?: string }[];
28
  }[],
29
) {
30
  const url = new URL(`https://api.xero.com/payroll.xro/1.0/PayrollCalendars`);
31

32
  const response = await fetch(url, {
33
    method: "POST",
34
    headers: {
35
      Accept: 'application/json',
36
      "Xero-Tenant-Id": Xero_Tenant_Id,
37
      "Idempotency-Key": Idempotency_Key,
38
      "Content-Type": "application/json",
39
      Authorization: "Bearer " + auth.token,
40
    },
41
    body: JSON.stringify(body),
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49