//native
type Zoho = {
token: string;
};
/**
* Email statement
* Email statement to the contact. If JSONString is not inputted, mail will be sent with the default mail content.
*/
export async function main(
auth: Zoho,
contact_id: string,
organization_id: string | undefined,
start_date: string | undefined,
end_date: string | undefined,
multipart_or_formdata: string | undefined,
body: {
send_from_org_email_id?: false | true;
to_mail_ids: string[];
cc_mail_ids?: string[];
subject: string;
body: string;
},
) {
const url = new URL(
`https://www.zohoapis.com/inventory/v1/contacts/${contact_id}/statements/email`,
);
for (const [k, v] of [
["organization_id", organization_id],
["start_date", start_date],
["end_date", end_date],
["multipart_or_formdata", multipart_or_formdata],
]) {
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