Get Contact

Script hubspot Verified

by daltonpoubrebrurf ยท 6/6/2022

The script

Submitted by hugo989 Bun
Verified 2 days ago
1
import { Client } from "@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

Other submissions
  • Submitted by adam186 Deno
    Created 394 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