Edits history of script submission #21151 for ' Categorize an uncategorized transaction (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Categorize an uncategorized transaction
     * Categorize an uncategorized transaction by creating a new transaction.
     */
    export async function main(
      auth: Zoho,
      transaction_id: string,
      organization_id: string | undefined,
      body: {
        from_account_id?: string;
        to_account_id?: string;
        transaction_type: string;
        amount?: number;
        date?: string;
        reference_number?: string;
        payment_mode?: string;
        exchange_rate?: number;
        description?: string;
        customer_id?: string;
        tags?: { tag_id?: number; tag_option_id?: number }[];
        documents?: { file_name?: {}; document_id?: {} }[];
        currency_id?: string;
        tax_id?: string;
        to_account_tags?: { tag_id?: number; tag_option_id?: number }[];
        from_account_tags?: { tag_id?: number; tag_option_id?: number }[];
        is_inclusive_tax?: false | true;
        bank_charges?: number;
        user_id?: number;
        tax_authority_id?: string;
        tax_exemption_id?: string;
        custom_fields?: {
          custom_field_id?: number;
          index?: number;
          label?: string;
          value?: string;
        }[];
        line_items?: {
          line_id?: number;
          account_id?: string;
          account_name?: string;
          description?: string;
          tax_amount?: number;
          tax_id?: string;
          tax_name?: string;
          tax_type?: string;
          tax_percentage?: number;
          item_total?: number;
          item_total_inclusive_of_tax?: number;
          item_order?: number;
          tags?: { tag_id?: number; tag_option_id?: number }[];
        }[];
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/books/v3/banktransactions/uncategorized/${transaction_id}/categorize`,
      );
      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