Edits history of script submission #21995 for ' Update a journal (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update a journal
     * Updates the journal with given information.
     */
    export async function main(
      auth: Zoho,
      journal_id: string,
      organization_id: string | undefined,
      body: {
        journal_date: string;
        reference_number?: string;
        notes?: string;
        journal_type?: string;
        vat_treatment?: string;
        include_in_vat_return?: false | true;
        product_type?: string;
        is_bas_adjustment?: false | true;
        currency_id?: string;
        exchange_rate?: number;
        location_id?: string;
        line_items?: {
          account_id?: string;
          customer_id?: string;
          line_id?: string;
          description?: string;
          tax_exemption_id?: string;
          tax_authority_id?: string;
          tax_exemption_type?: string;
          tax_exemption_code?: string;
          tax_authority_name?: string;
          tax_id?: string;
          amount: number;
          debit_or_credit: string;
          acquisition_vat_id?: string;
          reverse_charge_vat_id?: string;
          tags?: { tag_id?: number; tag_option_id?: number }[];
          location_id?: string;
          project_id?: string;
        }[];
        tax_exemption_code?: string;
        tax_exemption_type?: string;
        custom_fields?: { customfield_id?: string; value?: string }[];
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/books/v3/journals/${journal_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