//native
type Zoho = {
token: string;
};
/**
* Update a contact
* Update an existing contact. To delete a contact person remove it from the contact_persons list.
*/
export async function main(
auth: Zoho,
contact_id: string,
organization_id: string | undefined,
body: {
contact_name: string;
company_name?: string;
payment_terms?: number;
currency_id?: string;
contact_type?: string;
website?: string;
custom_fields?: { value?: string; index?: number; label?: string }[];
opening_balances?: {
location_id?: string;
exchange_rate?: number;
opening_balance_amount?: number;
}[];
billing_address?: {
attention?: string;
address?: string;
street2?: string;
city?: string;
state?: string;
zip?: string;
country?: string;
};
shipping_address?: {
attention?: string;
address?: string;
street2?: string;
city?: string;
state?: string;
zip?: string;
country?: string;
};
contact_persons?: {
salutation?: string;
first_name?: string;
last_name?: string;
email?: string;
phone?: string;
mobile?: string;
is_primary_contact?: false | true;
}[];
default_templates?: {
invoice_template_id?: string;
invoice_template_name?: string;
estimate_template_id?: string;
estimate_template_name?: string;
creditnote_template_id?: string;
creditnote_template_name?: string;
invoice_email_template_id?: string;
invoice_email_template_name?: string;
estimate_email_template_id?: string;
estimate_email_template_name?: string;
creditnote_email_template_id?: string;
creditnote_email_template_name?: string;
};
language_code?: string;
notes?: string;
vat_reg_no?: string;
tax_reg_no?: string;
country_code?: string;
tax_treatment?: string;
tax_regime?: string;
legal_name?: string;
is_tds_registered?: false | true;
vat_treatment?: string;
avatax_exempt_no?: string;
avatax_use_code?: string;
tax_exemption_id?: string;
tax_authority_id?: string;
tax_id?: false | true;
is_taxable?: false | true;
facebook?: string;
twitter?: string;
place_of_contact?: string;
gst_no?: string;
gst_treatment?: string;
tax_authority_name?: string;
tax_exemption_code?: string;
},
) {
const url = new URL(
`https://www.zohoapis.com/inventory/v1/contacts/${contact_id}`,
);
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: {
"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