//native
type Kustomer = {
apiKey: string;
};
/**
* Update company attributes
* Updates the attributes of a company based on the company ID.
*/
export async function main(
auth: Kustomer,
id: string,
body: {
name?: string;
externalId?: string;
avatarUrl?: string;
emails?: {
type?: "home" | "work" | "other";
email: string;
verified?: false | true;
}[];
phones?: {
type?: "home" | "work" | "other" | "mobile" | "fax";
phone: string;
verified?: false | true;
}[];
whatsapps?: { type?: "mobile"; phone: string; verified?: false | true }[];
socials?: {
type: "twitter" | "facebook" | "instagram" | "linkedin" | "pinterest";
userid?: string;
username: string;
url?: string;
verified?: false | true;
}[];
urls?: { type?: "other" | "website" | "blog"; url: string }[];
domains?: { domain: string }[];
locations?: {
type?: "home" | "work" | "other";
name?: string;
address?: string;
address2?: string;
address3?: string;
latitude?: number;
longitude?: number;
countryCode?: string;
countryName?: string;
regionCode?: string;
regionName?: string;
cityName?: string;
zipCode?: string;
areaCode?: string;
}[];
employeeCount?: number;
tags?: string[];
custom?: {};
defaultLang?: string;
rev?: number;
deleted?: false | true;
},
) {
const url = new URL(`https://api.kustomerapp.com/v1/companies/${id}`);
const response = await fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.apiKey,
},
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