//native
type Zoho = {
token: string;
};
/**
* Email a credit note
* Email a credit note.
*/
export async function main(
auth: Zoho,
creditnote_id: string,
organization_id: string | undefined,
customer_id: string | undefined,
attachments: string | undefined,
body: {
to_mail_ids: string[];
cc_mail_ids?: string[];
subject: string;
body: string;
},
) {
const url = new URL(
`https://www.zohoapis.com/inventory/v1/creditnotes/${creditnote_id}/email`,
);
for (const [k, v] of [
["organization_id", organization_id],
["customer_id", customer_id],
["attachments", attachments],
]) {
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