⚙ Operations Hub

JErickson60
Membre

Need to query all custom objects associated to a contact and pull a single property from each

Résolue

Need to query all custom objects associated to a contact and pull a single property from each one to add to a contact.

 

So we have custom objects called "Buildings" and a given contact can have multiple "Buildings" Associated. I need to know if i can use a workflow to query all associated "Buildings", not just most recently updated, and pull a single property, "Building ID" to be able to add it to a property on the contact record.

 

If this cannot be done via regular workflow does anyone know by chance if a custom coded api workflow can achieve this?

0 Votes
2 Solutions acceptées
Kevin-C
Solution
Expert reconnu | Partenaire solutions
Expert reconnu | Partenaire solutions

Need to query all custom objects associated to a contact and pull a single property from each

Résolue

Hey @JErickson60 

 

To start @PamCotton 's ideas are the right direction, to paint a little more context:

 

You can use the graphql API to get all buildings w/ the building_id property associate to a contact in a workflow:

query MyQuery {
  CRM {
    contact(uniqueIdentifier: "hs_object_id", uniqueIdentifierValue: "44139400962") {
      associations {
        p_buildings_collection__contact_to_buildings {
          items {
            building_id
          }
        }
      }
    }
  }
}

This query is requesting all buildings  w/ their building_ids associated to contact with a record ID of  "44139400962".

 

The response will look somethign like:

{
"data": {
    "CRM": {
      "contact": {
        "associations": {
          "p_buildings_collection__contact_to_buildings": {
            "items": [
              {
                "building_id": "6565"
              },
              {
                "building_id": "34232"
              }
            ]
          }
        }
      }
    }
  }
}

 

You can then loop throught the buildings to output a list of the bulding IDs:

const buildingIds = response.data.CRM.Contact.Associations.p_buildings_collection__contact_to_buildings.items.map(obj => obj.building_id);

Finnaly this can then be output from the custom code action and applied to the contact record property.

 

Now if you only want a single  building_id you'll need additional logic to determine which building_id is the correct ID.

 

Hope this gets you going!

If I can clarify or help further in any way please don't hesitate to reach out!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev

Voir la solution dans l'envoi d'origine

0 Votes
RThomas7
Solution
Participant

Need to query all custom objects associated to a contact and pull a single property from each

Résolue

hey there @JErickson60 you can do this with a custom code action via the API:
1. use this endpoint to retrieve all of the associated Buildings of a the enrolled Contact (by Record ID) https://developers.hubspot.com/docs/api/crm/associations/v3#:~:text=Retrieve%20associations,values%2....

2. use this endpoint to read the Building ID property value from the specified Building by including its record ID.  Endpoint: /crm/v3/objects/{objectType}/{objectId}
Docs: https://developers.hubspot.com/docs/api/crm/crm-custom-objects

3. use this endpoint to update (append the Building ID) the contact's property for storing the associated Building ID(s).

Endpoint: PATCH/crm/v3/objects/contacts/{contactId}
Docs: https://developers.hubspot.com/docs/api/crm/contacts

 

Here's documentation on how to use Custom Code Actions in HubSpot:
https://developers.hubspot.com/docs/api/workflows/custom-code-actions

 

Voir la solution dans l'envoi d'origine

3 Réponses
RThomas7
Solution
Participant

Need to query all custom objects associated to a contact and pull a single property from each

Résolue

hey there @JErickson60 you can do this with a custom code action via the API:
1. use this endpoint to retrieve all of the associated Buildings of a the enrolled Contact (by Record ID) https://developers.hubspot.com/docs/api/crm/associations/v3#:~:text=Retrieve%20associations,values%2....

2. use this endpoint to read the Building ID property value from the specified Building by including its record ID.  Endpoint: /crm/v3/objects/{objectType}/{objectId}
Docs: https://developers.hubspot.com/docs/api/crm/crm-custom-objects

3. use this endpoint to update (append the Building ID) the contact's property for storing the associated Building ID(s).

Endpoint: PATCH/crm/v3/objects/contacts/{contactId}
Docs: https://developers.hubspot.com/docs/api/crm/contacts

 

Here's documentation on how to use Custom Code Actions in HubSpot:
https://developers.hubspot.com/docs/api/workflows/custom-code-actions

 

Kevin-C
Solution
Expert reconnu | Partenaire solutions
Expert reconnu | Partenaire solutions

Need to query all custom objects associated to a contact and pull a single property from each

Résolue

Hey @JErickson60 

 

To start @PamCotton 's ideas are the right direction, to paint a little more context:

 

You can use the graphql API to get all buildings w/ the building_id property associate to a contact in a workflow:

query MyQuery {
  CRM {
    contact(uniqueIdentifier: "hs_object_id", uniqueIdentifierValue: "44139400962") {
      associations {
        p_buildings_collection__contact_to_buildings {
          items {
            building_id
          }
        }
      }
    }
  }
}

This query is requesting all buildings  w/ their building_ids associated to contact with a record ID of  "44139400962".

 

The response will look somethign like:

{
"data": {
    "CRM": {
      "contact": {
        "associations": {
          "p_buildings_collection__contact_to_buildings": {
            "items": [
              {
                "building_id": "6565"
              },
              {
                "building_id": "34232"
              }
            ]
          }
        }
      }
    }
  }
}

 

You can then loop throught the buildings to output a list of the bulding IDs:

const buildingIds = response.data.CRM.Contact.Associations.p_buildings_collection__contact_to_buildings.items.map(obj => obj.building_id);

Finnaly this can then be output from the custom code action and applied to the contact record property.

 

Now if you only want a single  building_id you'll need additional logic to determine which building_id is the correct ID.

 

Hope this gets you going!

If I can clarify or help further in any way please don't hesitate to reach out!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Votes
PamCotton
Gestionnaire de communauté
Gestionnaire de communauté

Need to query all custom objects associated to a contact and pull a single property from each

Résolue

Hey @JErickson60, welcome to our Community!

 

To query all custom objects (like "Buildings") associated with a contact and pull a single property (such as "Building ID") to add to a contact's record, you can't do this directly with HubSpot's native workflows.

However, you can use custom coded workflow actions. Here's a brief overview:

 

  1. Create a custom coded action in your workflow.
  2. Use HubSpot's API to get all custom objects associated with the contact and extract the "Building ID" from each.
  3. Update the contact record with the collected "Building IDs".

To our top experts, @DanielSanchez and @Anton do you have any recommendations for @JErickson60 matter?

 

Thank you,

Pam

Você sabia que a Comunidade está disponível em outros idiomas?
Participe de conversas regionais, alterando suas configurações de idioma !


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !