//native
type Zoho = {
token: string;
};
/**
* Create a Recurring Invoice
* Creating a new recurring invoice.
*/
export async function main(
auth: Zoho,
organization_id: string | undefined,
body: {
recurrence_name: string;
reference_number?: string;
customer_id: string;
currency_id?: string;
contact_persons?: string[];
place_of_supply?: string;
vat_treatment?: string;
gst_treatment?: string;
tax_treatment?: string;
is_reverse_charge_applied?: false | true;
cfdi_usage?: string;
allow_partial_payments?: false | true;
gst_no?: string;
start_date?: string;
end_date?: string;
recurrence_frequency: "weeks";
repeat_every?: number;
location_id?: string;
line_items?: {
line_item_id?: string;
quantity?: number;
name?: string;
item_total?: number;
product_type?: string;
hsn_or_sac?: string;
sat_item_key_code?: string;
unitkey_code?: string;
tags?: { tag_id?: string; tag_option_id?: string }[];
location_id?: string;
tax_id?: {};
tds_tax_id?: string;
tax_treatment_code?: string;
project_id?: string;
header_name?: string;
}[];
tax_id?: {};
custom_fields?: { value?: string; label?: string; data_type?: string }[];
email?: string;
billing_address?: {
address?: string;
street2?: string;
city?: string;
state?: string;
zip?: string;
country?: string;
fax?: string;
};
shipping_address?: {
address?: string;
city?: string;
state?: string;
zip?: string;
country?: string;
fax?: string;
};
avatax_use_code?: string;
avatax_exempt_no?: string;
template_id?: string;
payment_terms?: number;
payment_terms_label?: string;
tax_authority_id?: string;
tax_exemption_id?: string;
exchange_rate?: string;
payment_options?: {
payment_gateways?: {
configured?: false | true;
additional_field1?: string;
gateway_name?: string;
}[];
};
discount?: string;
is_discount_before_tax?: false | true;
discount_type?: string;
is_inclusive_tax?: false | true;
item_id?: string;
name?: string;
description?: string;
rate?: number;
quantity?: number;
unit?: string;
avatax_tax_code?: string;
salesperson_name?: string;
shipping_charge?: number;
adjustment?: number;
adjustment_description?: string;
},
) {
const url = new URL(`https://www.zohoapis.com/books/v3/recurringinvoices`);
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