//native
type Zoho = {
token: string;
};
/**
* Search records
*
*/
export async function main(
auth: Zoho,
module_api_name: string,
criteria: string | undefined,
email: string | undefined,
phone: string | undefined,
word: string | undefined,
converted: string | undefined,
approved: string | undefined,
page: string | undefined,
per_page: string | undefined,
fields: string | undefined,
cvid: string | undefined,
_type: string | undefined,
X_EXTERNAL?: string,
) {
const url = new URL(`https://zohoapis.com/crm/v8/${module_api_name}/search`);
for (const [k, v] of [
["criteria", criteria],
["email", email],
["phone", phone],
["word", word],
["converted", converted],
["approved", approved],
["page", page],
["per_page", per_page],
["fields", fields],
["cvid", cvid],
["type", _type],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
...(X_EXTERNAL ? { "X-EXTERNAL": X_EXTERNAL } : {}),
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