APIs & Integrations

AMorales7
Participant

Associate a Standard and Custom Object

SOLVE

Hello All! 

 

New to HubSpot and was looking to associate Contacts to 'Custom_Object_x' in our instance. Would I use the instructions here (https://legacydocs.hubspot.com/docs/methods/crm-associations/associate-objects) to 'Associate Custom Objects'? How would I define cardinality? (Do I need to define it?) It would be a one to many in this case.

 

Is there an example call you used? I have just started working with HubSpots APIs and would greatly appreciate any guidance. 

1 Accepted solution
miljkovicmisa
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Associate a Standard and Custom Object

SOLVE

Hello @AMorales7 , associations for custom objects are created automatically for some standard objects as per the documentation in this link. This means that the moment you create a custom object there are association definitions automatically created between the custom object and email, meeting_event, note, task, call, and conversation_session.


So the first thing to do is check the existing associations and their ids with POST https://api.hubapi.com/crm/v3/schemas/{objectType}/associations

As for the cardinality so far I think it's defaulted by hubspot you can define it with the associations endpoint but overwriting it won't work as expected, I have tried changing the association between my custom object and contacts to be ONE TO ONE / ONE_TO_MANY (one contact per custom object/many custom objects per contact) like below, it kind of worked but in the hubspot panel interface I could still choose multiple objects (contacts) but only the last one selected would stay (works but buggy).
So with a POST to https://api.hubapi.com/crm/v3/schemas/{CUSTOM_OBJECT_ID}/associations

 

         {
            "fromObjectTypeId": "<CUSTOM_OBJECT_ID>",
            "toObjectTypeId": "<TARGET_OBJECT_ID>",
            "name": "<ASSOCIATION_NAME>",
            "cardinality": "ONE_TO_ONE",
            "inverseCardinality": "ONE_TO_MANY",
            "id": "<ASSOCIATION_ID>"
        },
        {
            "fromObjectTypeId": "<TARGET_OBJECT_ID>",
            "toObjectTypeId": "<CUSTOM_OBJECT_ID>",
            "name": "<INVERSE_ASSOCIATION_NAME>",
            "cardinality": "ONE_TO_MANY",
            "inverseCardinality": "ONE_TO_ONE",
            "id": "<INVERSE_ASSOCIATION_ID>"
        }

 


At last I'm attatching this link here where there is some discussion related to this topic.
If you need further assistance don't hesitate to write here.

There is also this great resource in this link right here that might help you get started

If my answer was helpful please mark it as a solution.

@dennisedson see I'm into API's too!!! Please tag other people who you think might be of help, I haven't made any friends here yet (except of you ofcourse) 😛

View solution in original post

4 Replies 4
AGaardsted
Participant

Associate a Standard and Custom Object

SOLVE

@miljkovicmisa Purhaps you have an answer to my problem with Custom Objects as well.

I need to include custom object (CO) tokens in automated mails with standard objects:

1. Contact properties

2.  Associated CO properties

3. Deal properties.

 

I've made the custom object (called Recipients) through API, and the object have a one-to-many relation with Deal object.  In other words the Recipent can have several Deals, but the Deal can only have one Recipient. 
I want to be able to include a contacts name, as well as the Recipient name, and the Deal name, but the Deal-centeret flow does not seem to pull the associated object property. The contact name is no problem.

 

I hope someone can help.

 

Thank you

Andreas

webdew
Guide | Diamond Partner
Guide | Diamond Partner

Associate a Standard and Custom Object

SOLVE

Hi @AMorales7 ,

You can use this documentation for Custom_Object_x associate to Custom_Object_y
Link : https://developers.hubspot.com/blog/introducing-custom-objects-for-hubspot


Hope this helps!


If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

miljkovicmisa
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Associate a Standard and Custom Object

SOLVE

Hello @AMorales7 , associations for custom objects are created automatically for some standard objects as per the documentation in this link. This means that the moment you create a custom object there are association definitions automatically created between the custom object and email, meeting_event, note, task, call, and conversation_session.


So the first thing to do is check the existing associations and their ids with POST https://api.hubapi.com/crm/v3/schemas/{objectType}/associations

As for the cardinality so far I think it's defaulted by hubspot you can define it with the associations endpoint but overwriting it won't work as expected, I have tried changing the association between my custom object and contacts to be ONE TO ONE / ONE_TO_MANY (one contact per custom object/many custom objects per contact) like below, it kind of worked but in the hubspot panel interface I could still choose multiple objects (contacts) but only the last one selected would stay (works but buggy).
So with a POST to https://api.hubapi.com/crm/v3/schemas/{CUSTOM_OBJECT_ID}/associations

 

         {
            "fromObjectTypeId": "<CUSTOM_OBJECT_ID>",
            "toObjectTypeId": "<TARGET_OBJECT_ID>",
            "name": "<ASSOCIATION_NAME>",
            "cardinality": "ONE_TO_ONE",
            "inverseCardinality": "ONE_TO_MANY",
            "id": "<ASSOCIATION_ID>"
        },
        {
            "fromObjectTypeId": "<TARGET_OBJECT_ID>",
            "toObjectTypeId": "<CUSTOM_OBJECT_ID>",
            "name": "<INVERSE_ASSOCIATION_NAME>",
            "cardinality": "ONE_TO_MANY",
            "inverseCardinality": "ONE_TO_ONE",
            "id": "<INVERSE_ASSOCIATION_ID>"
        }

 


At last I'm attatching this link here where there is some discussion related to this topic.
If you need further assistance don't hesitate to write here.

There is also this great resource in this link right here that might help you get started

If my answer was helpful please mark it as a solution.

@dennisedson see I'm into API's too!!! Please tag other people who you think might be of help, I haven't made any friends here yet (except of you ofcourse) 😛

AMorales7
Participant

Associate a Standard and Custom Object

SOLVE

Incredibly helpful miljkovicmisa!!  Many thanks for all the great detail. I dug into the docs you sent over the weekend. Quick question. If I wanted to check associations and get their ID's as you mentioned wouldnt I use a GET call vs a POST? 

0 Upvotes