Edits history of script submission #21220 for ' Create a vendor credit (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a vendor credit
     * Create a vendor credit for a vendor.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      ignore_auto_number_generation: string | undefined,
      bill_id: string | undefined,
      body: {
        vendor_id: string;
        vat_treatment?: string;
        vendor_credit_number?: string;
        gst_treatment?: string;
        tax_treatment?: string;
        gst_no?: string;
        source_of_supply?: string;
        destination_of_supply?: string;
        place_of_supply?: string;
        pricebook_id?: string;
        reference_number?: string;
        is_update_customer?: false | true;
        date?: string;
        exchange_rate?: number;
        is_inclusive_tax?: false | true;
        location_id?: string;
        line_items?: {
          item_id?: string;
          line_item_id?: string;
          account_id?: string;
          name?: string;
          hsn_or_sac?: string;
          reverse_charge_tax_id?: string;
          location_id?: string;
          description?: string;
          item_order?: number;
          quantity?: number;
          unit?: string;
          rate?: number;
          tax_id?: string;
          tds_tax_id?: string;
          tax_treatment_code?: string;
          tags?: { tag_id?: number; tag_option_id?: number }[];
          item_custom_fields?: {
            custom_field_id?: number;
            label?: string;
            value?: string;
            index?: number;
          }[];
          serial_numbers?: string[];
          project_id?: string;
          project_name?: string;
        }[];
        notes?: string;
        documents?: { document_id?: number; file_name?: string }[];
        custom_fields?: {
          custom_field_id?: number;
          label?: string;
          value?: string;
          index?: number;
        }[];
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/inventory/v1/vendorcredits`);
      for (const [k, v] of [
        ["organization_id", organization_id],
        ["ignore_auto_number_generation", ignore_auto_number_generation],
        ["bill_id", bill_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