//native
type Zoho = {
token: string;
};
/**
* Create an invoice
* Create an invoice for your customer.
*/
export async function main(
auth: Zoho,
organization_id: string | undefined,
send: string | undefined,
ignore_auto_number_generation: string | undefined,
body: {
customer_id: string;
contact_persons?: {
contact_person_id?: string;
salutation?: string;
first_name?: string;
last_name?: string;
email?: {};
phone?: string;
mobile?: string;
is_primary_contact?: {};
}[];
invoice_number?: string;
reference_number?: string;
template_id?: string;
date?: string;
payment_terms?: number;
payment_terms_label?: string;
due_date?: string;
discount?: number;
is_discount_before_tax?: false | true;
discount_type?: string;
is_inclusive_tax?: false | true;
exchange_rate?: number;
recurring_invoice_id?: string;
invoiced_estimate_id?: string;
salesperson_name?: string;
custom_fields?: {
index?: number;
show_on_pdf?: false | true;
value?: string;
label?: string;
}[];
project_id?: string;
line_items: {
line_item_id?: string;
item_id?: string;
project_id?: string;
time_entry_ids?: string;
expense_id?: string;
expense_receipt_name?: string;
name?: string;
description?: string;
item_order?: number;
bcy_rate?: number;
rate?: number;
quantity?: number;
unit?: string;
discount_amount?: number;
discount?: number;
tax_id?: string;
tds_tax_id?: string;
tax_name?: string;
tax_type?: string;
tax_percentage?: number;
item_total?: number;
salesorder_item_id?: number;
location_id?: string;
hsn_or_sac?: string;
sat_item_key_code?: string;
unitkey_code?: string;
}[];
location_id?: string;
payment_options?: {
payment_gateways?: {
configured?: false | true;
additional_field1?: string;
gateway_name?: string;
}[];
};
allow_partial_payments?: false | true;
custom_body?: string;
custom_subject?: string;
notes?: string;
terms?: string;
shipping_charge?: string;
adjustment?: number;
adjustment_description?: string;
reason?: string;
tax_authority_id?: string;
tax_exemption_id?: string;
avatax_use_code?: string;
avatax_exempt_no?: string;
vat_treatment?: string;
tax_treatment?: string;
billing_address_id?: number;
shipping_address_id?: number;
gst_no?: string;
gst_treatment?: string;
place_of_supply?: string;
cfdi_usage?: string;
},
) {
const url = new URL(`https://www.zohoapis.com/inventory/v1/invoices`);
for (const [k, v] of [
["organization_id", organization_id],
["send", send],
["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