Edits history of script submission #21195 for ' Create a credit note (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a credit note
     * To create a credit note for a customer.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      invoice_id: string | undefined,
      ignore_auto_number_generation: string | undefined,
      body: {
        customer_id: string;
        contact_persons?: string[];
        date: string;
        is_draft?: false | true;
        exchange_rate?: string;
        line_items: {
          item_id?: string;
          description?: string;
          code?: string;
          name?: string;
          type?: number;
          account_id?: string;
          account_name?: string;
          quantity?: number;
          tax_id?: string;
          tds_tax_id?: string;
          product_type?: string;
          sat_item_key_code?: string;
          unitkey_code?: string;
          serial_numbers?: string;
          location_id?: string;
          invoice_id?: string;
          invoice_item_id?: string;
          is_item_shipped?: false | true;
          is_returned_to_stock?: false | true;
          salesreturn_item_id?: string;
        }[];
        location_id?: string;
        creditnote_number: string;
        gst_treatment?: string;
        tax_treatment?: string;
        gst_no?: string;
        cfdi_usage?: string;
        cfdi_reference_type?: string;
        place_of_supply?: string;
        ignore_auto_number_generation?: false | true;
        reference_number?: string;
        custom_fields?: { value?: string; index?: number; label?: string }[];
        notes?: string;
        terms?: string;
        template_id?: string;
        tax_id?: string;
        tax_authority_id?: string;
        tax_exemption_id?: string;
        avatax_use_code?: string;
        avatax_exempt_no?: string;
        vat_treatment?: string;
        is_inclusive_tax?: false | true;
        avatax_tax_code?: string;
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/inventory/v1/creditnotes`);
      for (const [k, v] of [
        ["organization_id", organization_id],
        ["invoice_id", invoice_id],
        ["ignore_auto_number_generation", ignore_auto_number_generation],
      ]) {
        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