//native
type Zoho = {
token: string;
};
/**
* Get related record
*
*/
export async function main(
auth: Zoho,
module_api_name: string,
record_id: string,
related_list_api_name: string,
related_record_id: string,
fields: string | undefined,
If_Modified_Since?: string,
X_EXTERNAL?: string,
) {
const url = new URL(
`https://zohoapis.com/crm/v8/${module_api_name}/${record_id}/${related_list_api_name}/${related_record_id}`,
);
for (const [k, v] of [["fields", fields]]) {
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