//native
type Zoho = {
token: string;
};
/**
* Create a location
* Create a location.
*/
export async function main(
auth: Zoho,
organization_id: string | undefined,
body: {
type?: string;
email?: string;
phone?: string;
address?: {
city?: string;
state?: string;
country?: string;
attention?: string;
state_code?: string;
street_address1?: string;
street_address2?: string;
};
location_name: string;
tax_settings_id: string;
parent_location_id?: string;
associated_series_ids?: string[];
auto_number_generation_id?: string;
is_all_users_selected?: false | true;
user_ids?: string;
},
) {
const url = new URL(`https://www.zohoapis.com/inventory/v1/locations`);
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