//native
type Pipedrive = {
apiToken: string;
};
/**
* Get all archived deals
* Returns data about all archived deals.
*/
export async function main(
auth: Pipedrive,
filter_id: string | undefined,
ids: string | undefined,
owner_id: string | undefined,
person_id: string | undefined,
org_id: string | undefined,
pipeline_id: string | undefined,
stage_id: string | undefined,
status: "open" | "won" | "lost" | "deleted" | undefined,
updated_since: string | undefined,
updated_until: string | undefined,
sort_by: "id" | "update_time" | "add_time" | undefined,
sort_direction: "asc" | "desc" | undefined,
include_fields:
| "next_activity_id"
| "last_activity_id"
| "first_won_time"
| "products_count"
| "files_count"
| "notes_count"
| "followers_count"
| "email_messages_count"
| "activities_count"
| "done_activities_count"
| "undone_activities_count"
| "participants_count"
| "last_incoming_mail_time"
| "last_outgoing_mail_time"
| undefined,
custom_fields: string | undefined,
limit: string | undefined,
cursor: string | undefined,
) {
const url = new URL(`https://api.pipedrive.com/api/v2/deals/archived`);
for (const [k, v] of [
["filter_id", filter_id],
["ids", ids],
["owner_id", owner_id],
["person_id", person_id],
["org_id", org_id],
["pipeline_id", pipeline_id],
["stage_id", stage_id],
["status", status],
["updated_since", updated_since],
["updated_until", updated_until],
["sort_by", sort_by],
["sort_direction", sort_direction],
["include_fields", include_fields],
["custom_fields", custom_fields],
["limit", limit],
["cursor", cursor],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"x-api-token": auth.apiToken,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago