//native
type Zoho = {
token: string;
};
/**
* Update
*
*/
export async function main(
auth: Zoho,
id: string,
_module: string | undefined,
body: {
custom_views: {
display_value: string;
system_name: string;
category: string;
created_time: string;
modified_time: string;
last_accessed_time: string;
name: string;
created_by: { name: string; id: string; email?: string };
modified_by: { name: string; id: string; email?: string };
module: { name: string; id: string; email?: string };
criteria: {
comparator: string;
field: { api_name: string; id: string };
value: {};
group_operator: string;
group: {}[];
};
default: false | true;
system_defined: false | true;
locked: false | true;
favorite: number;
offline: false | true;
access_type: "shared" | "public" | "only_to_me";
shared_to: {
type: "territories" | "roles" | "groups" | "users";
name: string;
id: string;
subordinates: false | true;
}[];
fields: { id: string; api_name: string; _pin: false | true }[];
sort_by: { id: string; api_name: string };
sort_order: "asc" | "desc";
id: string;
}[];
},
) {
const url = new URL(
`https://zohoapis.com/crm/v8/settings/custom_views/${id}`,
);
for (const [k, v] of [["module", _module]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Zoho-oauthtoken " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago