0
Get Contact
One script reply has been approved by the moderators Verified
Created by daltonpoubrebrurf 683 days ago Viewed 4367 times
0
Submitted by adam186 Deno
Verified 501 days ago
1
import { Client } from "npm:@hubspot/api-client@^8.1.0";
2

3
/**
4
 * @param properties List of the properties to be returned in the response.
5
 *
6
 * @param properties_with_history List of the properties to be returned
7
 * along with their history of previous values.
8
 */
9
type Hubspot = {
10
  token: string;
11
};
12
export async function main(
13
  auth: Hubspot,
14
  contact_id: string,
15
  properties?: string[],
16
  properties_with_history?: string[],
17
) {
18
  const client = new Client({
19
    accessToken: auth.token,
20
  });
21

22
  try {
23
    return await client.crm.contacts.basicApi.getById(
24
      contact_id,
25
      getProp(properties),
26
      getProp(properties_with_history),
27
    );
28
  } catch (e) {
29
    throw Error(`
30
      ${e.code}\n
31
      Message: ${e.body.message || e.body}\n
32
    `);
33
  }
34
}
35

36
function getProp(prop?: string[]) {
37
  return Array.isArray(prop) && prop.length ? prop : undefined;
38
}
39