//native
type Zoho = {
token: string;
};
/**
* Upload photo
*
*/
export async function main(
auth: Zoho,
module_api_name: string,
id: string,
restrict_triggers: string | undefined,
body: { file?: {} },
) {
const url = new URL(
`https://zohoapis.com/crm/v8/${module_api_name}/${id}/photo`,
);
for (const [k, v] of [["restrict_triggers", restrict_triggers]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const formData = new FormData();
for (const [k, v] of Object.entries(body)) {
if (v !== undefined && v !== "") {
formData.append(k, String(v));
}
}
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: "Zoho-oauthtoken " + auth.token,
},
body: formData,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago