Edits history of script submission #10187 for ' Creates one or more tax rates (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
      token: string;
    };
    /**
     * Creates one or more tax rates
     *
     */
    export async function main(
      auth: Xero,
      xero_tenant_id: string,
      Idempotency_Key: string,
      body: {
        TaxRates?: {
          Name?: string;
          TaxType?: string;
          TaxComponents?: {
            Name?: string;
            Rate?: number;
            IsCompound?: false | true;
            IsNonRecoverable?: false | true;
          }[];
          Status?: "ACTIVE" | "DELETED" | "ARCHIVED" | "PENDING";
          ReportTaxType?:
            | "AVALARA"
            | "BASEXCLUDED"
            | "CAPITALSALESOUTPUT"
            | "CAPITALEXPENSESINPUT"
            | "ECOUTPUT"
            | "ECOUTPUTSERVICES"
            | "ECINPUT"
            | "ECACQUISITIONS"
            | "EXEMPTEXPENSES"
            | "EXEMPTINPUT"
            | "EXEMPTOUTPUT"
            | "GSTONIMPORTS"
            | "INPUT"
            | "INPUTTAXED"
            | "MOSSSALES"
            | "NONE"
            | "NONEOUTPUT"
            | "OUTPUT"
            | "PURCHASESINPUT"
            | "SALESOUTPUT"
            | "EXEMPTCAPITAL"
            | "EXEMPTEXPORT"
            | "CAPITALEXINPUT"
            | "GSTONCAPIMPORTS"
            | "GSTONCAPITALIMPORTS"
            | "REVERSECHARGES"
            | "PAYMENTS"
            | "INVOICE"
            | "CASH"
            | "ACCRUAL"
            | "FLATRATECASH"
            | "FLATRATEACCRUAL"
            | "ACCRUALS"
            | "TXCA"
            | "SRCAS"
            | "DSOUTPUT"
            | "BLINPUT2"
            | "EPINPUT"
            | "IMINPUT2"
            | "MEINPUT"
            | "IGDSINPUT2"
            | "ESN33OUTPUT"
            | "OPINPUT"
            | "OSOUTPUT"
            | "TXN33INPUT"
            | "TXESSINPUT"
            | "TXREINPUT"
            | "TXPETINPUT"
            | "NRINPUT"
            | "ES33OUTPUT"
            | "ZERORATEDINPUT"
            | "ZERORATEDOUTPUT"
            | "DRCHARGESUPPLY"
            | "DRCHARGE"
            | "CAPINPUT"
            | "CAPIMPORTS"
            | "IMINPUT"
            | "INPUT2"
            | "CIUINPUT"
            | "SRINPUT"
            | "OUTPUT2"
            | "SROUTPUT"
            | "CAPOUTPUT"
            | "SROUTPUT2"
            | "CIUOUTPUT"
            | "ZROUTPUT"
            | "ZREXPORT"
            | "ACC28PLUS"
            | "ACCUPTO28"
            | "OTHEROUTPUT"
            | "SHOUTPUT"
            | "ZRINPUT"
            | "BADDEBT"
            | "OTHERINPUT"
            | "BADDEBTRELIEF"
            | "IGDSINPUT3"
            | "SROVR"
            | "TOURISTREFUND"
            | "TXRCN33"
            | "TXRCRE"
            | "TXRCESS"
            | "TXRCTS"
            | "CAPEXINPUT"
            | "UNDEFINED"
            | "CAPEXOUTPUT"
            | "ZEROEXPOUTPUT"
            | "GOODSIMPORT"
            | "NONEINPUT"
            | "NOTREPORTED"
            | "SROVRRS"
            | "SROVRLVG"
            | "SRLVG"
            | "IM"
            | "IMESS"
            | "IMN33"
            | "IMRE"
            | "BADDEBTRECOVERY"
            | "USSALESTAX"
            | "BLINPUT3";
          CanApplyToAssets?: false | true;
          CanApplyToEquity?: false | true;
          CanApplyToExpenses?: false | true;
          CanApplyToLiabilities?: false | true;
          CanApplyToRevenue?: false | true;
          DisplayTaxRate?: number;
          EffectiveRate?: number;
        }[];
      },
    ) {
      const url = new URL(`https://api.xero.com/api.xro/2.0/TaxRates`);
    
      const response = await fetch(url, {
        method: "PUT",
        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