Edits history of script submission #21182 for ' Create a Bill (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a Bill
     * Creates a Bill in Zoho Inventory. Description about the extra parameter attachment Allowed extensions are gif, png, jpeg, jpg, bmp and pdf.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      body: {
        purchaseorder_id?: number;
        vendor_id: number;
        bill_number: string;
        date: string;
        due_date: string;
        reference_number?: string;
        currency_id?: number;
        exchange_rate?: number;
        is_item_level_tax_calc?: false | true;
        notes?: string;
        terms?: string;
        is_inclusive_tax?: false | true;
        custom_fields?: { customfield_id?: number; value?: string }[];
        line_items: {
          purchaseorder_item_id?: number;
          receive_item_id?: number;
          line_item_id?: number;
          name?: string;
          account_id?: number;
          account_name?: string;
          description?: string;
          bcy_rate?: number;
          rate?: number;
          quantity?: number;
          tax_id?: number;
          tds_tax_id?: string;
          tax_name?: string;
          tax_type?: string;
          tax_percentage?: number;
          item_total?: number;
          item_order?: number;
          unit?: string;
          image_id?: number;
          image_name?: string;
          image_type?: string;
          reverse_charge_tax_id?: string;
          hsn_or_sac?: string;
          tax_exemption_code?: string;
          location_id?: string;
          tax_exemption_id?: string;
        }[];
        location_id?: string;
        gst_treatment?: string;
        tax_treatment?: string;
        gst_no?: string;
        source_of_supply?: string;
        destination_of_supply?: string;
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/inventory/v1/bills`);
      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