import { Client } from "npm:@hubspot/api-client@^8.1.0";
import type { AssociationSpec } from "npm:@hubspot/api-client@^8.1.0/lib/codegen/crm/contacts/index.js";
type Hubspot = {
token: string;
};
export async function main(
auth: Hubspot,
contact_id: number,
to_object_type: string,
to_object_id: number,
associations: AssociationSpec[],
) {
const client = new Client({
accessToken: auth.token,
});
try {
associations =
associations?.map((c) => {
return typeof c === "string" ? JSON.parse(c) : c;
}) || [];
} catch (error) {
throw Error(`Tried to parse "associations" argument because
it was an array of strings but failed with error:\n${error}
Associations must have the following shape:
{
associationCategory: 'HUBSPOT_DEFINED' | 'USER_DEFINED' | 'INTEGRATOR_DEFINED',
associationTypeId: number
}
`);
}
try {
return await client.crm.contacts.associationsApi.create(
contact_id,
to_object_type,
to_object_id,
associations,
);
} catch (e) {
throw Error(`
${e.code}\n
Message: ${e.body.message || e.body}\n
`);
}
}
Submitted by admin 460 days ago
import { Client } from "npm:@hubspot/api-client@^8.1.0"
import type { AssociationSpec } from "npm:@hubspot/api-client@^8.1.0/lib/codegen/crm/contacts/index.js";
type Hubspot = {
token: string;
};
export async function main(
auth: Hubspot,
contact_id: number,
to_object_type: string,
to_object_id: number,
associations: AssociationSpec[]
) {
const client = new Client({
accessToken: auth.token
})
try {
associations = associations?.map(c => {
return typeof c === 'string' ? JSON.parse(c) : c
}) || []
} catch(error) {
throw Error(`Tried to parse "associations" argument because
it was an array of strings but failed with error:\n${error}
Associations must have the following shape:
{
associationCategory: 'HUBSPOT_DEFINED' | 'USER_DEFINED' | 'INTEGRATOR_DEFINED',
associationTypeId: number
}
`)
}
try {
return await client.crm.contacts.associationsApi.create(
contact_id,
to_object_type,
to_object_id,
associations
)
} catch (e) {
throw Error(`
${e.code}\n
Message: ${e.body.message || e.body}\n
`)
}
}
Submitted by admin 463 days ago
import * as wmill from "https://deno.land/x/windmill@v1.85.0/mod.ts"
import { Client } from "npm:@hubspot/api-client@^8.1.0"
import type { AssociationSpec } from "npm:@hubspot/api-client@^8.1.0/lib/codegen/crm/contacts/index.js";
export async function main(
auth: wmill.Resource<"hubspot">,
contact_id: number,
to_object_type: string,
to_object_id: number,
associations: AssociationSpec[]
) {
const client = new Client({
accessToken: auth.token
})
try {
associations = associations?.map(c => {
return typeof c === 'string' ? JSON.parse(c) : c
}) || []
} catch(error) {
throw Error(`Tried to parse "associations" argument because
it was an array of strings but failed with error:\n${error}
Associations must have the following shape:
{
associationCategory: 'HUBSPOT_DEFINED' | 'USER_DEFINED' | 'INTEGRATOR_DEFINED',
associationTypeId: number
}
`)
}
try {
return await client.crm.contacts.associationsApi.create(
contact_id,
to_object_type,
to_object_id,
associations
)
} catch (e) {
throw Error(`
${e.code}\n
Message: ${e.body.message || e.body}\n
`)
}
}
Submitted by adam186 592 days ago
import * as wmill from "https://deno.land/x/windmill@v1.70.1/mod.ts"
import { Client } from "npm:@hubspot/api-client@^8.1.0"
import type { AssociationSpec } from "npm:@hubspot/api-client@^8.1.0/lib/codegen/crm/contacts/index.js";
export async function main(
auth: wmill.Resource<"hubspot">,
contact_id: number,
to_object_type: string,
to_object_id: number,
associations: AssociationSpec[]
) {
const client = new Client({
accessToken: auth.token
})
try {
associations = associations?.map(c => {
return typeof c === 'string' ? JSON.parse(c) : c
}) || []
} catch(error) {
throw Error(`Tried to parse "associations" argument because
it was an array of strings but failed with error:\n${error}
Associations must have the following shape:
{
associationCategory: 'HUBSPOT_DEFINED' | 'USER_DEFINED' | 'INTEGRATOR_DEFINED',
associationTypeId: number
}
`)
}
try {
return await client.crm.contacts.associationsApi.create(
contact_id,
to_object_type,
to_object_id,
associations
)
} catch (e) {
throw Error(`
${e.code}\n
Message: ${e.body.message || e.body}\n
`)
}
}
Submitted by adam186 626 days ago
import * as wmill from "https://deno.land/x/windmill@v1.52.0/mod.ts"
import { Client } from "npm:@hubspot/api-client@^8.1.0"
import type { AssociationSpec } from "npm:@hubspot/api-client@^8.1.0/lib/codegen/crm/contacts/index.js";
export async function main(
auth: wmill.Resource<"hubspot">,
contact_id: number,
to_object_type: string,
to_object_id: number,
associations: AssociationSpec[]
) {
const client = new Client({
accessToken: auth.token
})
try {
associations = associations?.map(c => {
return typeof c === 'string' ? JSON.parse(c) : c
}) || []
} catch(error) {
throw Error(`Tried to parse "associations" argument because
it was an array of strings but failed with error:\n${error}
Associations must have the following shape:
{
associationCategory: 'HUBSPOT_DEFINED' | 'USER_DEFINED' | 'INTEGRATOR_DEFINED',
associationTypeId: number
}
`)
}
try {
return await client.crm.contacts.associationsApi.create(
contact_id,
to_object_type,
to_object_id,
associations
)
} catch (e) {
throw Error(`
${e.code}\n
Message: ${e.body.message || e.body}\n
`)
}
}
Submitted by adam186 711 days ago