APIs & Integrations

GregP
Contributor

Get Associated Object Properties in Custom Code Action

SOLVE

I'm working on a custom code action for a workflow and need to get the value of some properties of some associated custom objects for a deal.

It seems like I would grab the object id of the associated object with:

 

hubspotClient.crm.deals.associationsApi.getAll({deal_id}, {object_type_id})

 

 

 


then get the properties with something like (?) :

 

hubspotClient.crm.objects.basicApi.getById({id}, ['property1', 'property2'])

 

 

 

 

I don't really know how to get the id out of the first one (what does it return?), and I think I'm missing something in the second one. How should this be done, and could it be done with a single request?

Also, if there is any documentation on this Node.js SDK yet, please point me to it, as I've only come across a few code examples, and no real documentation. This is the most I've been able to find:
https://github.com/HubSpot/hubspot-api-nodejs/blob/302786dbb6d75aa6f127f18740c3218688e9cf36/README.m...

1 Accepted solution
GregP
Solution
Contributor

Get Associated Object Properties in Custom Code Action

SOLVE

Okay, here's what I've gotten to work:

hubspotClient.crm.deals.associationsApi.getAll({deal_id}, {object_typeid})
.then(function(results){
  {object_id} = results.body.results[0].id;
})
.then(function() {
  return hubspotClient.crm.objects.basicApi.getById({object_typeid}, {object_id}, ['foo']);
})
.then(function(results) {
    foo = results.body.properties.foo;	
})

View solution in original post

10 Replies 10
louischausse
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Get Associated Object Properties in Custom Code Action

SOLVE

What I want to know is if you make the calls in the same custom code action or in 2 separate custom code actions

Louis Chaussé from Auxilio HubSpot Solutions Partner Signature
Louis Chaussé from Auxilio HubSpot Solutions Partner Meeting link
0 Upvotes
GregP
Contributor

Get Associated Object Properties in Custom Code Action

SOLVE

Same custom code action.

0 Upvotes
louischausse
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Get Associated Object Properties in Custom Code Action

SOLVE

@GregP  Sorry for the delayed answer. 

 

In my opinion you can't do this in the same call so I think what you did is the best way to do it.

Louis Chaussé from Auxilio HubSpot Solutions Partner Signature
Louis Chaussé from Auxilio HubSpot Solutions Partner Meeting link
0 Upvotes
louischausse
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Get Associated Object Properties in Custom Code Action

SOLVE

ok can you send me a screenshot of the worklow where you run those code snippets please?

Louis Chaussé from Auxilio HubSpot Solutions Partner Signature
Louis Chaussé from Auxilio HubSpot Solutions Partner Meeting link
0 Upvotes
GregP
Contributor

Get Associated Object Properties in Custom Code Action

SOLVE

The example code above is way more readable for just this question. It has the call to the deal, to get the id of the associated object, and then a call to the associated object to get it's properties. The questions is if there is a way to directly get the properties of the associated object, without having to do a separate call to first get the id of the associated object.

0 Upvotes
GregP
Contributor

Get Associated Object Properties in Custom Code Action

SOLVE

In regard to the first part, it looks like this gives me the object id of the first returned object (we only associate one, so that works for my use):

results.body.results[0].id

Having that second "results" feels a bit odd semantically.

 

Still figuring out the second part.

0 Upvotes
GregP
Solution
Contributor

Get Associated Object Properties in Custom Code Action

SOLVE

Okay, here's what I've gotten to work:

hubspotClient.crm.deals.associationsApi.getAll({deal_id}, {object_typeid})
.then(function(results){
  {object_id} = results.body.results[0].id;
})
.then(function() {
  return hubspotClient.crm.objects.basicApi.getById({object_typeid}, {object_id}, ['foo']);
})
.then(function(results) {
    foo = results.body.properties.foo;	
})
louischausse
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Get Associated Object Properties in Custom Code Action

SOLVE

Hi @GregP ,

 

Have you resolved your problem yourself or you still need help?

If you have found your answer you should mark this post as resolved. If not, I'd be happy to help 🙂

Louis Chaussé from Auxilio HubSpot Solutions Partner Signature
Louis Chaussé from Auxilio HubSpot Solutions Partner Meeting link
GregP
Contributor

Get Associated Object Properties in Custom Code Action

SOLVE

I found something that works, but left open as I had also asked if there was a way to do this with a single request. That is still unanswered.

dennisedson
HubSpot Product Team
HubSpot Product Team

Get Associated Object Properties in Custom Code Action

SOLVE

@PCarlson@albertomedina , @louischausse  any of you able to lend a hand here?

@GregP, I agree that we need to get more documentation on the various libraries.  I can say that this is being worked on. Hoping we have more available sooner than later!

0 Upvotes