0
Create Contact
One script reply has been approved by the moderators Verified
Created by maximespengesys 625 days ago Viewed 266 times
0
Submitted by adam186 Deno
Verified 444 days ago
1
import { removeObjectEmptyFields } from "https://deno.land/x/windmill_helpers@v1.0.0/mod.ts";
2
import { Client } from "npm:@hubspot/api-client@^8.1.0";
3

4
type Hubspot = {
5
  token: string;
6
};
7
export async function main(
8
  auth: Hubspot,
9
  company?: string,
10
  email?: string,
11
  firstname?: string,
12
  lastname?: string,
13
  phone?: string,
14
  website?: string,
15
) {
16
  const client = new Client({
17
    accessToken: auth.token,
18
  });
19
  const properties = removeObjectEmptyFields({
20
    company,
21
    email,
22
    firstname,
23
    lastname,
24
    phone,
25
    website,
26
  });
27
  try {
28
    return await client.crm.contacts.basicApi.create({ properties });
29
  } catch (e) {
30
    throw Error(`
31
      ${e.code} - ${e.body.category}\n
32
      Message: ${e.body.message}\n
33
      Correlation ID: ${e.body.correlationId}
34
    `);
35
  }
36
}
37