1 | |
2 |
|
3 | |
4 | * Get Deal |
5 | * Retrieve a deal by record ID (or by a unique property via `id_property`), with the properties and associated object types you list. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Hubspot, |
9 | deal_id: string, |
10 | properties: string[] | undefined, |
11 | properties_with_history: string[] | undefined, |
12 | associations: string[] | undefined, |
13 | archived: boolean | undefined, |
14 | id_property: string | undefined |
15 | ) { |
16 | const url = new URL(`https://api.hubapi.com/crm/v3/objects/deals/${deal_id}`) |
17 | if (properties?.length) |
18 | url.searchParams.append("properties", properties.join(",")) |
19 | if (properties_with_history?.length) |
20 | url.searchParams.append( |
21 | "propertiesWithHistory", |
22 | properties_with_history.join(",") |
23 | ) |
24 | if (associations?.length) |
25 | url.searchParams.append("associations", associations.join(",")) |
26 | if (archived) url.searchParams.append("archived", String(archived)) |
27 | if (id_property != null && id_property !== "") |
28 | url.searchParams.append("idProperty", id_property) |
29 |
|
30 | const response = await fetch(url, { |
31 | headers: { |
32 | Authorization: `Bearer ${auth.token}`, |
33 | Accept: "application/json", |
34 | }, |
35 | }) |
36 |
|
37 | if (!response.ok) { |
38 | throw new Error(`${response.status} ${await response.text()}`) |
39 | } |
40 |
|
41 | return await response.json() |
42 | } |
43 |
|