Edits history of script submission #21197 for ' Create a fixed asset (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a fixed asset
     * Create a fixed asset.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      body: {
        asset_name: string;
        fixed_asset_type_id: string;
        asset_account_id: string;
        expense_account_id?: string;
        depreciation_account_id?: string;
        depreciation_method?: string;
        depreciation_frequency?: string;
        depreciation_percentage?: number;
        total_life?: number;
        salvage_value?: string;
        depreciation_start_date?: string;
        description?: string;
        asset_cost: number;
        computation_type?: string;
        warranty_expiry_date?: string;
        asset_purchase_date: string;
        serial_no?: string;
        dep_start_value?: number;
        notes?: string;
        tags?: { tag_id?: string; tag_option_id?: string }[];
        custom_fields?: { customfield_id?: string; value?: string }[];
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/books/v3/fixedassets`);
      for (const [k, v] of [["organization_id", organization_id]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "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