APIs & Integrations

PCarlson
Participant

associationType string values in nodejs

SOLVE

I'm trying to create a simple association between a contact and a deal in nodejs library, specifically using typescript, but cannot find documentation on the associationType string or the toObjectType to use.

 

There is a legacy list of Definition IDs here, but I am using the version 3 nodejs library, which asks for a string in the typescript type definitions like:

 

    /**
     *
     * @summary Associate a contact with another object
     * @param contactId
     * @param toObjectType
     * @param toObjectId
     * @param associationType
     */
    create(contactId: string, toObjectType: string, toObjectId: string, associationType: string, options?: {
        headers: {
            [name: string]: string;
        };
    }): Promise<{
        response: http.IncomingMessage;
        body: SimplePublicObject;
    }>;

 

The first 3 parameters seem obvious, but note that associationType is a string, not a number as given in the legacy docs. Is there a list like this for v3 library api?

 

More generally, is there a standard place to find documents with this type of definition?

 

https://developers.hubspot.com/docs/api/crm/deals gives the Endpoint descriptions for deals, but does not give the associationType values. https://github.com/HubSpot/hubspot-api-nodejs gives some examples and sample apps, but no comprehensive documentation. So I find myself bouncing between these and digging through the typescript .d.ts files and using VS Code intellisense to figure out what parameters I need.

 

A document defining standard strings to use for toObjectType, associationType and similar strings would be welcome and very valuable.

 

Thanks

 

Phil

0 Upvotes
1 Accepted solution
PCarlson
Solution
Participant

associationType string values in nodejs

SOLVE

I found that calling the associationsApi for existing associations gives me the type that I can then use to create an association.

 

So I can get and view the association like this:

const result = await hubspotClient.crm.contacts.associationsApi.getAll(contactId,'deal');
console.log(JSON.stringify(result.body.results))

and it shows output for existing related deals like this:

[{"id":"1234567890","type":"contact_to_deal"}]

 

This gives me a way to find any given associationType if I really want to verify it. It also corroborates my guess that it is the module names with "_to_" in between so they should generally be easy to guess.

 

I have not yet verified that I can create the association using that associationType, but I expect that to work.

 

Of course a full list would be welcome, or a better way that does not require that I create an association through the UI and write dummy code to show it. But this lets me move on.

 

Phil

View solution in original post

5 Replies 5
RMones
Contributor | Platinum Partner
Contributor | Platinum Partner

associationType string values in nodejs

SOLVE

Hi @PCarlson ,

 

I don't know if this will help with your problem, but I encounted the same issues.

I've used the Schema endpoint to check the associations.

 

https://api.hubapi.com/crm/v3/schemas/contacts
(https://developers.hubspot.com/docs/api/crm/crm-custom-objects

 

Greets Ronald

PCarlson
Participant

associationType string values in nodejs

SOLVE

Thanks @RMones 

 

I'll take a look at the Schema endpoint this weekend.

 

Phil

PCarlson
Solution
Participant

associationType string values in nodejs

SOLVE

I found that calling the associationsApi for existing associations gives me the type that I can then use to create an association.

 

So I can get and view the association like this:

const result = await hubspotClient.crm.contacts.associationsApi.getAll(contactId,'deal');
console.log(JSON.stringify(result.body.results))

and it shows output for existing related deals like this:

[{"id":"1234567890","type":"contact_to_deal"}]

 

This gives me a way to find any given associationType if I really want to verify it. It also corroborates my guess that it is the module names with "_to_" in between so they should generally be easy to guess.

 

I have not yet verified that I can create the association using that associationType, but I expect that to work.

 

Of course a full list would be welcome, or a better way that does not require that I create an association through the UI and write dummy code to show it. But this lets me move on.

 

Phil

dennisedson
HubSpot Product Team
HubSpot Product Team

associationType string values in nodejs

SOLVE

Hi @PCarlson 

Thanks for writing this out.  We are working hard on creating and updating documentation to be more consistent.  We will also be focusing on creating more sample projects for the various libraries.  Although I do not have anything for you now, I just want you to know that your voice is not unheard here.

0 Upvotes
PCarlson
Participant

associationType string values in nodejs

SOLVE

Thanks for the reply Dennis,

 

Lost in my focus on the documentation was that my purpose in posting was to find the associationType to use to relate a contact to a deal.

 

Is that "contact_to_deal"?

 

Is that the general layout (i.e. "module1_to_module2") so I can guess and try it for other associationType values?

 

Thanks

 

Phil

0 Upvotes