//native
type Zoho = {
token: string;
};
/**
* Upload file
*
*/
export async function main(
auth: Zoho,
body: { file: {} },
feature?: string,
X_CRM_ORG?: string,
) {
const url = new URL(`https://zohoapis.com/crm/v8/upload`);
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: {
...(feature ? { feature: feature } : {}),
...(X_CRM_ORG ? { "X-CRM-ORG": X_CRM_ORG } : {}),
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