//native
type Pipedrive = {
apiToken: string;
};
/**
* Add a new activity
* Adds a new activity.
*/
export async function main(
auth: Pipedrive,
body: {
subject?: string;
type?: string;
owner_id?: number;
deal_id?: number;
lead_id?: string;
person_id?: number;
org_id?: number;
project_id?: number;
due_date?: string;
due_time?: string;
duration?: string;
busy?: false | true;
done?: false | true;
location?: {
value?: string;
country?: string;
admin_area_level_1?: string;
admin_area_level_2?: string;
locality?: string;
sublocality?: string;
route?: string;
street_number?: string;
postal_code?: string;
};
participants?: { person_id?: number; primary?: false | true }[];
attendees?: {
email?: string;
name?: string;
status?: string;
is_organizer?: false | true;
person_id?: number;
user_id?: number;
}[];
public_description?: string;
priority?: number;
note?: string;
},
) {
const url = new URL(`https://api.pipedrive.com/api/v2/activities`);
const response = await fetch(url, {
method: "POST",
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