//native
type Zoho = {
token: string;
};
/**
* Update a project using a custom field's unique value
* A custom field will have unique values if it's configured to not accept duplicate values.
*/
export async function main(
auth: Zoho,
organization_id: string | undefined,
X_Unique_Identifier_Key: string,
X_Unique_Identifier_Value: string,
body: {
project_name: string;
customer_id: string;
currency_id?: string;
description?: string;
billing_type: string;
rate?: string;
budget_type?: string;
budget_hours?: string;
budget_amount?: string;
cost_budget_amount?: number;
user_id: string;
tasks?: {
task_name: string;
description?: string;
rate?: string;
budget_hours?: string;
}[];
users?: {
user_id?: string;
is_current_user?: false | true;
user_name?: string;
email?: string;
user_role?: string;
status?: string;
rate?: string;
budget_hours?: string;
total_hours?: string;
billed_hours?: string;
un_billed_hours?: string;
cost_rate?: number;
}[];
},
X_Upsert?: string,
) {
const url = new URL(`https://www.zohoapis.com/books/v3/projects`);
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: "PUT",
headers: {
"X-Unique-Identifier-Key": X_Unique_Identifier_Key,
"X-Unique-Identifier-Value": X_Unique_Identifier_Value,
...(X_Upsert ? { "X-Upsert": X_Upsert } : {}),
"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