0

Get deal products of several deals

by
Published Oct 17, 2025

Returns data about products attached to deals

Script pipedrive Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Pipedrive = {
3
  apiToken: string;
4
};
5
/**
6
 * Get deal products of several deals
7
 * Returns data about products attached to deals
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  deal_ids: string | undefined,
12
  cursor: string | undefined,
13
  limit: string | undefined,
14
  sort_by: "id" | "deal_id" | "add_time" | "update_time" | undefined,
15
  sort_direction: "asc" | "desc" | undefined,
16
) {
17
  const url = new URL(`https://api.pipedrive.com/api/v2/deals/products`);
18
  for (const [k, v] of [
19
    ["deal_ids", deal_ids],
20
    ["cursor", cursor],
21
    ["limit", limit],
22
    ["sort_by", sort_by],
23
    ["sort_direction", sort_direction],
24
  ]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      "x-api-token": auth.apiToken,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42