//native
type Pipedrive = {
apiToken: string;
};
/**
* Update a person
* Updates the properties of a person.
*/
export async function main(
auth: Pipedrive,
id: string,
body: {
name?: string;
owner_id?: number;
org_id?: number;
add_time?: string;
update_time?: string;
emails?: { value?: string; primary?: false | true; label?: false | true }[];
phones?: { value?: string; primary?: false | true; label?: false | true }[];
visible_to?: number;
label_ids?: number[];
},
) {
const url = new URL(`https://api.pipedrive.com/api/v2/persons/${id}`);
const response = await fetch(url, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"x-api-token": auth.apiToken,
},
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