//native
type Zoho = {
token: string;
};
/**
* Create an organization
* Create an organization.
*/
export async function main(
auth: Zoho,
organization_id: string | undefined,
body: {
name: string;
fiscal_year_start_month?: string;
currency_code: string;
time_zone: string;
date_format?: string;
field_separator?: string;
language_code?: string;
industry_type?: string;
industry_size?: string;
portal_name: string;
org_address?: string;
remit_to_address?: string;
address?: {
street_address1?: string;
street_address2?: string;
city?: string;
state?: string;
country?: string;
zip?: string;
}[];
},
) {
const url = new URL(`https://www.zohoapis.com/inventory/v1/organizations`);
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