//native
type Zoho = {
token: string;
};
/**
* Email a sales order
* Email a sales order to the customer. Input json string is not mandatory. If input json string is empty, mail will be send with default mail content.
*/
export async function main(
auth: Zoho,
salesorder_id: string,
organization_id: string | undefined,
attachments: string | undefined,
send_attachment: string | undefined,
file_name: string | undefined,
body: {
from_address_id?: string;
send_from_org_email_id?: false | true;
to_mail_ids: string[];
cc_mail_ids?: string[];
bcc_mail_ids?: string[];
subject: string;
documents?: string;
invoice_id?: string;
body: string;
},
) {
const url = new URL(
`https://www.zohoapis.com/books/v3/salesorders/${salesorder_id}/email`,
);
for (const [k, v] of [
["organization_id", organization_id],
["attachments", attachments],
["send_attachment", send_attachment],
["file_name", file_name],
]) {
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