0
Create Deal
One script reply has been approved by the moderators Verified
Created by armancekpboi 893 days ago Viewed 9164 times
0
Submitted by adam186 Deno
Verified 710 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
/**
5
 * @param closedate Uses the following date-time format:
6
 * `2019-12-07T16:50:06.678Z` but time value can be omitted.
7
 */
8
type Hubspot = {
9
  token: string;
10
};
11
export async function main(
12
  auth: Hubspot,
13
  amount?: string,
14
  closedate?: string,
15
  dealname?: string,
16
  dealstage?: string,
17
  hubspot_owner_id?: string,
18
  pipeline?: string,
19
) {
20
  const client = new Client({
21
    accessToken: auth.token,
22
  });
23
  const properties = removeObjectEmptyFields({
24
    amount,
25
    closedate,
26
    dealname,
27
    dealstage,
28
    hubspot_owner_id,
29
    pipeline,
30
  });
31
  try {
32
    return await client.crm.deals.basicApi.create({ properties });
33
  } catch (e) {
34
    throw Error(`
35
      ${e.code} - ${e.body.category}\n
36
      Message: ${e.body.message}\n
37
      Correlation ID: ${e.body.correlationId}
38
    `);
39
  }
40
}
41