//native
type Zoho = {
token: string;
};
/**
* Add a task
* The task has been added.
*/
export async function main(
auth: Zoho,
project_id: string,
organization_id: string | undefined,
body: {
task_name: string;
description?: string;
rate?: number;
budget_hours?: number;
},
) {
const url = new URL(
`https://www.zohoapis.com/books/v3/projects/${project_id}/tasks`,
);
for (const [k, v] of [["organization_id", organization_id]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
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