APIs & Integrations

Jun22
Teilnehmer/-in

Display Associations Array Value

lösung
Hello Guys Need Help,

I made display the deals associated with the company using API integrations I have api endpoint below with "Properties and Asssociations".
https://api.hubapi.com/crm/v3/objects/deals?limit=10&properties=hubspot_owner_id&pro[…]ge&associatio...
 I have image below with a deal and I need to get the company name and associated contact from the deal. It display on array display the properties value like dealname is showing. But when try to pull the data on "associations" like. contact, company it shows undefine

here's my sample code to pull the Properties and Associations from a table only associations is not working:

 

var table = document.getElementById("demoB").getElementsByTagName('tbody')[0];
           filtered_results.forEach((element, index, array) => {

var row = table.insertRow();
var cell = row.insertCell();

cell.innerHTML = element['associations']['company'];
cell = row.insertCell();
cell.innerHTML = element['properties']['hubspot_owner_id'];​

 


The [''associations']['company'] is showing underfined.
while properties is showing. 😔



Jun22_1-1679459182448.pngJun22_3-1679459257630.png

 

Jun22_0-1679459075702.png

 

2 Akzeptierte Lösungen
albertsg
Lösung
Ratgeber/-in

Display Associations Array Value

lösung

Hello @Jun22, I believe you are not accessing properly the values inside 'associations'. Notice that the structure of 'associations' and 'properties' is different.

 

I recommend you to debug it by printing every "step" with console.log to see where you are not accessing the data properly. 

 

Also, take a look at the accepted solution here, I'm sure it will help: https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-j... 

 



Did my answer help you? Mark it as a solution

You also connect with me on LinkedIn or Twitter

Lösung in ursprünglichem Beitrag anzeigen

GRajput
Lösung
Autorität | Platinum Partner
Autorität | Platinum Partner

Display Associations Array Value

lösung

Hi @Jun22 

Based on the code snippet you provided, it looks like you are trying to access the value of the "company" property from the "associations" object in your API response.
One possible reason why you are getting an "undefined" value for "element['associations']['company']" could be that the "associations" object does not have a "company" property. You can check the structure of the "associations" object by logging it to the console and see if it has a "company" property or not.
Another possible reason could be that the "company" property exists but its value is null or undefined in the API response. You can again log the value of "element['associations']['company']" to the console and check if it is null or undefined.
If you confirm that the "associations" object does have a "company" property and its value is not null or undefined, you can try accessing it using dot notation instead of bracket notation, like this:

cell.innerHTML = element.associations.company;
If dot notation still doesn't work, you can also try using the "getProperty" method of the "associations" object to access the value of the "company" property, like this:

arduino

cell.innerHTML = element.associations.getProperty('company');
Make sure to also check that the API endpoint you are using actually returns the "company" property in the "associations" object. If it doesn't, you might need to modify your API query to include the "company" property.

 

Please mark it as SOLUTION ACCEPTED if you like the solution.

Thank you!




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


Lösung in ursprünglichem Beitrag anzeigen

4 Antworten
GRajput
Lösung
Autorität | Platinum Partner
Autorität | Platinum Partner

Display Associations Array Value

lösung

Hi @Jun22 

Based on the code snippet you provided, it looks like you are trying to access the value of the "company" property from the "associations" object in your API response.
One possible reason why you are getting an "undefined" value for "element['associations']['company']" could be that the "associations" object does not have a "company" property. You can check the structure of the "associations" object by logging it to the console and see if it has a "company" property or not.
Another possible reason could be that the "company" property exists but its value is null or undefined in the API response. You can again log the value of "element['associations']['company']" to the console and check if it is null or undefined.
If you confirm that the "associations" object does have a "company" property and its value is not null or undefined, you can try accessing it using dot notation instead of bracket notation, like this:

cell.innerHTML = element.associations.company;
If dot notation still doesn't work, you can also try using the "getProperty" method of the "associations" object to access the value of the "company" property, like this:

arduino

cell.innerHTML = element.associations.getProperty('company');
Make sure to also check that the API endpoint you are using actually returns the "company" property in the "associations" object. If it doesn't, you might need to modify your API query to include the "company" property.

 

Please mark it as SOLUTION ACCEPTED if you like the solution.

Thank you!




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


albertsg
Lösung
Ratgeber/-in

Display Associations Array Value

lösung

Hello @Jun22, I believe you are not accessing properly the values inside 'associations'. Notice that the structure of 'associations' and 'properties' is different.

 

I recommend you to debug it by printing every "step" with console.log to see where you are not accessing the data properly. 

 

Also, take a look at the accepted solution here, I'm sure it will help: https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-j... 

 



Did my answer help you? Mark it as a solution

You also connect with me on LinkedIn or Twitter

Jun22
Teilnehmer/-in

Display Associations Array Value

lösung

Hello albertsg, 

Thanks i get now the results with similar documentation of the link you just shared. And it returns now with ID,

do you have any reference now that we can retrieved the deals endpoint to display Label name instead of ID's e.g "Owner Name, Company Name, and Contact Name."

0 Upvotes
Jaycee_Lewis
Community-Manager/-in
Community-Manager/-in

Display Associations Array Value

lösung

Hi, @Jun22 👋 Thanks for reaching out. Let's see if any of our community members have any JavaScript magic they can offer — hey @miljkovicmisa @MatthiasWeber @albertsg, do you have any experience here?

 

Thank you! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes