//native
type Zoho = {
token: string;
};
/**
* Create an item
* Creates a new item in Zoho Inventory.
*/
export async function main(
auth: Zoho,
organization_id: string | undefined,
body: {
group_id?: string;
group_name?: string;
unit?: string;
documents?: string[];
item_type?: string;
product_type?: string;
is_taxable?: false | true;
tax_id?: number;
description?: string;
purchase_account_id?: number;
inventory_account_id?: number;
attribute_name1?: string;
name: string;
rate?: number;
purchase_rate?: number;
reorder_level?: number;
locations?: {
location_id?: string;
initial_stock?: number;
initial_stock_rate?: number;
}[];
vendor_id?: number;
vendor_name?: string;
sku?: string;
upc?: number;
ean?: number;
isbn?: string;
part_number?: string;
attribute_option_name1?: number;
purchase_description?: string;
item_tax_preferences?: { tax_id?: number; tax_specification?: string }[];
hsn_or_sac?: string;
sat_item_key_code?: string;
unitkey_code?: string;
custom_fields?: { customfield_id?: number; value?: string }[];
},
) {
const url = new URL(`https://www.zohoapis.com/inventory/v1/items`);
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