0

Update a task

by
Published Oct 17, 2025

Update the details of a task.

Script zoho Verified

The script

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