CRM_Associations function for custom objects not working

Hello,

I am trying to fetch the associated custom objects to my contact into a landing page but not succeeding. Always returning “null”.

The code is working for normal objects, but not for custom objects:

{% if dynamic_page_crm_object %} 

{% set user = dynamic_page_crm_object %} 

<h1>{{user.firstname}} {{user.lastname}} <br/> {{user.email}} <br/> {{user.phone}} </h1>

{% set contact_id = user.hs_object_id %}

{% set custom_objects = crm_associations(contact_id, "USER_DEFINED", "_2_4948679", "property_name", false) %}

<p>{{custom_objects|pprint }}</p>

{% endif %}

Am I doing anything wrong with regard to custom objects?

Hi, @ChrisChiha :waving_hand: Thanks for reaching out! Hey, @Sjardo @Anton @tmcmillan99, do you have any experience or tips you can share with @ChrisChiha? Thank you very much for taking a look! — Jaycee

Hi @ChrisChiha ,

It seems that you are passing the Custom Object ID as the association definition ID, which will not work. You need to check what the ID is of your association between your contact object and your custom object. You can do so by retrieving your custom object schema.
You can make the API call from the docs itself, take a look at the ‘Get an existing schema’ part and add your custom object name or object type ID to the params. You can then make a test call on the right side.

Thanks, @Teun :raising_hands:

Happy to help!