//native
type Zoho = {
token: string;
};
/**
* Update an invoice using a custom field's unique value
* A custom field will have unique values if it's configured to not accept duplicate values.
*/
export async function main(
auth: Zoho,
organization_id: string | undefined,
X_Unique_Identifier_Key: string,
X_Unique_Identifier_Value: string,
body: {
customer_id: string;
currency_id?: string;
contact_persons?: string[];
invoice_number?: string;
place_of_supply?: string;
vat_treatment?: string;
tax_treatment?: string;
is_reverse_charge_applied?: false | true;
gst_treatment?: string;
cfdi_usage?: string;
cfdi_reference_type?: string;
reference_invoice_id?: string;
gst_no?: 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?: { customfield_id?: number; value?: string }[];
location_id?: string;
line_items: {
item_id: string;
project_id?: string;
time_entry_ids?: string[];
product_type?: string;
hsn_or_sac?: string;
sat_item_key_code?: string;
unitkey_code?: string;
location_id?: 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;
tags?: { tag_id?: string; tag_option_id?: string }[];
discount?: number;
tax_id?: string;
tds_tax_id?: string;
tax_name?: string;
tax_type?: string;
tax_percentage?: number;
tax_treatment_code?: string;
header_name?: string;
header_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;
tax_id?: string;
expense_id?: string;
salesorder_item_id?: string;
avatax_tax_code?: string;
line_item_id?: string;
},
X_Upsert?: string,
) {
const url = new URL(`https://www.zohoapis.com/books/v3/invoices`);
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: "PUT",
headers: {
"X-Unique-Identifier-Key": X_Unique_Identifier_Key,
"X-Unique-Identifier-Value": X_Unique_Identifier_Value,
...(X_Upsert ? { "X-Upsert": X_Upsert } : {}),
"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