Edits history of script submission #10502 for ' adds a fixed asset (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
      token: string;
    };
    /**
     * adds a fixed asset
     * Adds an asset to the system
     */
    export async function main(
      auth: Xero,
      xero_tenant_id: string,
      Idempotency_Key: string,
      body: {
        assetId?: string;
        assetName: string;
        assetTypeId?: string;
        assetNumber?: string;
        purchaseDate?: string;
        purchasePrice?: number;
        disposalDate?: string;
        disposalPrice?: number;
        assetStatus?: "Draft" | "Registered" | "Disposed";
        warrantyExpiryDate?: string;
        serialNumber?: string;
        bookDepreciationSetting?: {
          depreciationMethod?:
            | "NoDepreciation"
            | "StraightLine"
            | "DiminishingValue100"
            | "DiminishingValue150"
            | "DiminishingValue200"
            | "FullDepreciation";
          averagingMethod?: "FullMonth" | "ActualDays";
          depreciationRate?: number;
          effectiveLifeYears?: number;
          depreciationCalculationMethod?: "Rate" | "Life" | "None";
          depreciableObjectId?: string;
          depreciableObjectType?: string;
          bookEffectiveDateOfChangeId?: string;
        };
        bookDepreciationDetail?: {
          currentCapitalGain?: number;
          currentGainLoss?: number;
          depreciationStartDate?: string;
          costLimit?: number;
          residualValue?: number;
          priorAccumDepreciationAmount?: number;
          currentAccumDepreciationAmount?: number;
        };
        canRollback?: false | true;
        accountingBookValue?: number;
        isDeleteEnabledForDate?: false | true;
      },
    ) {
      const url = new URL(`https://api.xero.com/assets.xro/1.0/Assets`);
    
      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