Edits history of script submission #10147 for ' Creates a pay item (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
      token: string;
    };
    /**
     * Creates a pay item
     *
     */
    export async function main(
      auth: Xero,
      Xero_Tenant_Id: string,
      Idempotency_Key: string,
      body: {
        EarningsRates?: {
          Name?: string;
          AccountCode?: string;
          TypeOfUnits?: string;
          IsExemptFromTax?: false | true;
          IsExemptFromSuper?: false | true;
          IsReportableAsW1?: false | true;
          AllowanceContributesToAnnualLeaveRate?: false | true;
          AllowanceContributesToOvertimeRate?: false | true;
          EarningsType?:
            | "FIXED"
            | "ORDINARYTIMEEARNINGS"
            | "OVERTIMEEARNINGS"
            | "ALLOWANCE"
            | "LUMPSUMD"
            | "EMPLOYMENTTERMINATIONPAYMENT"
            | "LUMPSUMA"
            | "LUMPSUMB"
            | "BONUSESANDCOMMISSIONS"
            | "LUMPSUME"
            | "LUMPSUMW"
            | "DIRECTORSFEES"
            | "PAIDPARENTALLEAVE"
            | "WORKERSCOMPENSATION";
          EarningsRateID?: string;
          RateType?: "FIXEDAMOUNT" | "MULTIPLE" | "RATEPERUNIT";
          RatePerUnit?: string;
          Multiplier?: number;
          AccrueLeave?: false | true;
          Amount?: number;
          EmploymentTerminationPaymentType?: "O" | "R";
          UpdatedDateUTC?: string;
          CurrentRecord?: false | true;
          AllowanceType?:
            | "CAR"
            | "TRANSPORT"
            | "LAUNDRY"
            | "MEALS"
            | "TRAVEL"
            | "OTHER"
            | "TOOLS"
            | "TASKS"
            | "QUALIFICATIONS";
          AllowanceCategory?:
            | "TRANSPORT"
            | "OTHER"
            | "NONDEDUCTIBLE"
            | "UNIFORM"
            | "PRIVATEVEHICLE"
            | "HOMEOFFICE"
            | "GENERAL";
        }[];
        DeductionTypes?: {
          Name?: string;
          AccountCode?: string;
          ReducesTax?: false | true;
          ReducesSuper?: false | true;
          IsExemptFromW1?: false | true;
          DeductionTypeID?: string;
          UpdatedDateUTC?: string;
          DeductionCategory?: "NONE" | "UNIONFEES" | "WORKPLACEGIVING";
          CurrentRecord?: false | true;
        }[];
        LeaveTypes?: {
          Name?: string;
          TypeOfUnits?: string;
          LeaveTypeID?: string;
          NormalEntitlement?: number;
          LeaveLoadingRate?: number;
          UpdatedDateUTC?: string;
          IsPaidLeave?: false | true;
          ShowOnPayslip?: false | true;
          CurrentRecord?: false | true;
          LeaveCategoryCode?:
            | "ANNUALLEAVE"
            | "LONGSERVICELEAVE"
            | "PERSONALSICKCARERSLEAVE"
            | "ROSTEREDDAYOFF"
            | "TIMEOFFINLIEU"
            | "COMPASSIONATEANDBEREAVEMENTLEAVE"
            | "STUDYLEAVE"
            | "FAMILYANDDOMESTICVIOLENCELEAVE"
            | "SPECIALPAIDLEAVE"
            | "COMMUNITYSERVICELEAVE"
            | "JURYDUTYLEAVE"
            | "DEFENCERESERVELEAVE";
          SGCExempt?: false | true;
        }[];
        ReimbursementTypes?: {
          Name?: string;
          AccountCode?: string;
          ReimbursementTypeID?: string;
          UpdatedDateUTC?: string;
          CurrentRecord?: false | true;
        }[];
      },
    ) {
      const url = new URL(`https://api.xero.com/payroll.xro/1.0/PayItems`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Accept: 'application/json',
          "Xero-Tenant-Id": Xero_Tenant_Id,
          "Idempotency-Key": Idempotency_Key,
          "Content-Type": "application/json",
          Authorization: "Bearer " + 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 515 days ago