//native
type Zoho = {
token: string;
};
/**
* Update an item 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,
X_Upsert?: string,
body: {
name: string;
rate: number;
description?: string;
tax_id?: string;
purchase_tax_rule_id?: string;
sales_tax_rule_id?: string;
tax_percentage?: string;
hsn_or_sac?: string;
sat_item_key_code?: string;
unitkey_code?: string;
sku?: string;
product_type?: string;
is_taxable?: false | true;
tax_exemption_id?: string;
purchase_tax_exemption_id?: string;
account_id?: string;
avatax_tax_code?: string;
avatax_use_code?: string;
item_type?: string;
purchase_description?: string;
purchase_rate?: string;
purchase_account_id?: string;
inventory_account_id?: string;
vendor_id?: string;
reorder_level?: string;
locations?: {
location_id?: string;
initial_stock?: string;
initial_stock_rate?: string;
}[];
item_tax_preferences?: { tax_id?: string; tax_specification?: string }[];
custom_fields?: { customfield_id?: number; value?: string }[];
},
) {
const url = new URL(`https://www.zohoapis.com/books/v3/items`);
for (const [k, v] of [["organization_id", organization_id]]) {
if (v !== undefined && v !== "") {
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