//native
type Attio = {
token: string;
};
/**
* Assert a record
* Use this endpoint to create or update people, companies and other records.
*/
export async function main(
auth: Attio,
object: string,
matching_attribute: string | undefined,
body: { data: { values: {} } },
) {
const url = new URL(`https://api.attio.com/v2/objects/${object}/records`);
for (const [k, v] of [["matching_attribute", matching_attribute]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + 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 141 days ago