Edits history of script submission #22020 for ' Update a transaction (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update a transaction
     * Make changes in the applicable fields of a transaction and update it.
     */
    export async function main(
      auth: Zoho,
      bank_transaction_id: string,
      organization_id: string | undefined,
      body: {
        from_account_id?: string;
        to_account_id?: string;
        transaction_type: string;
        amount?: number;
        payment_mode?: string;
        exchange_rate?: number;
        date?: string;
        customer_id?: string;
        reference_number?: string;
        description?: string;
        currency_id?: string;
        tax_id?: string;
        is_inclusive_tax?: false | true;
        tags?: { tag_id?: number; tag_option_id?: number }[];
        from_account_tags?: { tag_id?: number; tag_option_id?: number }[];
        to_account_tags?: { tag_id?: number; tag_option_id?: number }[];
        documents?: { file_name?: {}; document_id?: {} }[];
        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/${bank_transaction_id}`,
      );
      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: "PUT",
        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