Edits history of script submission #228 for ' Create Associations (hubspot)'

  • deno
    One script reply has been approved by the moderators
    Ap­pro­ved
    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 hugo697 388 days ago

  • deno
    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 1020 days ago

  • deno
    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 1024 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/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 1152 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/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 1187 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/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 1271 days ago