//native
type Zoho = {
token: string;
};
/**
* Get record using external id
*
*/
export async function main(
auth: Zoho,
module_api_name: string,
external_field_value: string,
approved: string | undefined,
converted: string | undefined,
cvid: string | undefined,
uid: string | undefined,
fields: string | undefined,
startDateTime: string | undefined,
endDateTime: string | undefined,
territory_id: string | undefined,
include_child: string | undefined,
If_Modified_Since?: string,
X_EXTERNAL?: string,
) {
const url = new URL(
`https://zohoapis.com/crm/v8/${module_api_name}/${external_field_value}`,
);
for (const [k, v] of [
["approved", approved],
["converted", converted],
["cvid", cvid],
["uid", uid],
["fields", fields],
["startDateTime", startDateTime],
["endDateTime", endDateTime],
["territory_id", territory_id],
["include_child", include_child],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
...(If_Modified_Since ? { "If-Modified-Since": If_Modified_Since } : {}),
...(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