0

Add a task

by
Published Oct 17, 2025

The task has been added.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Add a task
7
 * The task has been added.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  project_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    task_name: string;
15
    description?: string;
16
    rate?: number;
17
    budget_hours?: number;
18
  },
19
) {
20
  const url = new URL(
21
    `https://www.zohoapis.com/books/v3/projects/${project_id}/tasks`,
22
  );
23
  for (const [k, v] of [["organization_id", organization_id]]) {
24
    if (v !== undefined && v !== "" && k !== undefined) {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "POST",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: "Zoho-oauthtoken " + auth.token,
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42