//native
type Zoho = {
token: string;
};
/**
* Get users
*
*/
export async function main(
auth: Zoho,
_type:
| "ActiveUsers"
| "CurrentUser"
| "ActiveConfirmedUsers"
| "DeactiveUsers"
| "NotConfirmedUsers"
| "ConfirmedUsers"
| undefined,
page: string | undefined,
per_page: string | undefined,
ids: string | undefined,
If_Modified_Since?: string,
X_ZOHO_SERVICE?: string,
X_ZCSRF_TOKEN?: string,
) {
const url = new URL(`https://zohoapis.com/crm/v8/users`);
for (const [k, v] of [
["type", _type],
["page", page],
["per_page", per_page],
["ids", ids],
]) {
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_ZOHO_SERVICE ? { "X-ZOHO-SERVICE": X_ZOHO_SERVICE } : {}),
...(X_ZCSRF_TOKEN ? { "X-ZCSRF-TOKEN": X_ZCSRF_TOKEN } : {}),
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