Edits history of script submission #21208 for ' Create a recurring expense (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a recurring expense
     * Create a recurring expense.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      body: {
        account_id: string;
        recurrence_name: string;
        start_date: string;
        end_date?: string;
        recurrence_frequency: string;
        repeat_every: string;
        gst_no?: string;
        source_of_supply?: string;
        destination_of_supply?: string;
        place_of_supply?: string;
        reverse_charge_tax_id?: string;
        location_id?: string;
        line_items?: {
          line_item_id?: string;
          account_id?: string;
          description?: string;
          amount?: number;
          tax_id?: string;
          item_order?: string;
          product_type?: string;
          acquisition_vat_id?: string;
          reverse_charge_vat_id?: string;
          reverse_charge_tax_id?: string;
          tax_exemption_code?: string;
          tax_exemption_id?: string;
        }[];
        amount: number;
        vat_treatment?: string;
        tax_treatment?: string;
        product_type?: string;
        acquisition_vat_id?: string;
        reverse_charge_vat_id?: string;
        tax_id?: string;
        is_inclusive_tax?: false | true;
        is_billable?: false | true;
        customer_id?: string;
        project_id?: string;
        currency_id?: string;
        exchange_rate?: number;
        custom_fields?: { customfield_id?: number; value?: string }[];
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/books/v3/recurringexpenses`);
      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