//native
type Zoho = {
token: string;
};
/**
* Get emails related records
*
*/
export async function main(
auth: Zoho,
module_name: string,
record_id: string,
_type:
| "all_contacts_draft_crm_emails"
| "all_contacts_scheduled_crm_emails"
| "all_contacts_sent_crm_emails"
| "sent_from_crm"
| "scheduled_in_crm"
| "drafts"
| "user_emails"
| undefined,
index: string | undefined,
owner_id: string | undefined,
) {
const url = new URL(
`https://zohoapis.com/crm/v8/${module_name}/${record_id}/Emails`,
);
for (const [k, v] of [
["type", _type],
["index", index],
["owner_id", owner_id],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Zoho-oauthtoken " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago