APIs & Integrations

Fred4
Membre

How to Perform Filtered Search for Events in Custom Objects?

Greetings, everyone,

 

I am working on an API integration between my app and HubSpot, where HubSpot serves as the database. I created a custom object called "Events," which is associated with a standard object "Company."

 

I would like to perform a filtered search for all events of a specific company associated with this event.

For this filter, when both objects are standard, the call should be: Captura de ecrã 2024-09-18, às 15.11.59.png

However, in the case of custom objects, I found the following information: Captura de ecrã 2024-09-18, às 15.12.26.png

I cannot find in the documentation how to perform this search for custom objects. I would like to know where I am going wrong or how I should make the correct call in this case.

Thank you in advance for any help!

0 Votes
1 Réponse
Jaycee_Lewis
Gestionnaire de communauté
Gestionnaire de communauté

How to Perform Filtered Search for Events in Custom Objects?

Hey, @Fred4 👋 Welcome to the community. To clarify, you are not missing an option with the Search API. You'll need to use the Associations API to return the objects IDs. The thing to note here is that the Associations API doesn't offer filtering or search operators. If you need to utilize those, you have to look at making multiple requests. One to the Search API to use filters and search operators on your Custom Object, and then one to use those IDs and use the Associations API to get the related company IDs. The other option is to look into GraphQL if you have a Content Hub — Professional or Enterprise subscription. 

 

I made a quick example of what the response will look like using the Associations API with a Custom Object.

Steps:

  • I have an existing Custom Object called Cats
  • It has two records
  • I have multiple test companies
  • I associated 6 companies to one of my cat records

Request

curl --request GET \
  --url 'https://api.hubapi.com/crm/v4/objects/cats/13466364256/associations/companies?limit=500' \
  --header 'authorization: Bearer YOUR_ACCESS_TOKEN'

Response

HTTP 200

{
  "results": [
    {
      "toObjectId": 11685858563,
      "associationTypes": [
        {
          "category": "USER_DEFINED",
          "typeId": 51,
          "label": null
        }
      ]
    },
    {
      "toObjectId": 11685858582,
      "associationTypes": [
        {
          "category": "USER_DEFINED",
          "typeId": 51,
          "label": null
        }
      ]
    },
    {
      "toObjectId": 13861282304,
      "associationTypes": [
        {
          "category": "USER_DEFINED",
          "typeId": 49,
          "label": "cat_co"
        },
        {
          "category": "USER_DEFINED",
          "typeId": 51,
          "label": null
        }
      ]
    },
    {
      "toObjectId": 15709311259,
      "associationTypes": [
        {
          "category": "USER_DEFINED",
          "typeId": 49,
          "label": "cat_co"
        },
        {
          "category": "USER_DEFINED",
          "typeId": 51,
          "label": null
        }
      ]
    },
    {
      "toObjectId": 16053398365,
      "associationTypes": [
        {
          "category": "USER_DEFINED",
          "typeId": 49,
          "label": "cat_co"
        },
        {
          "category": "USER_DEFINED",
          "typeId": 51,
          "label": null
        }
      ]
    },
    {
      "toObjectId": 20461937810,
      "associationTypes": [
        {
          "category": "USER_DEFINED",
          "typeId": 49,
          "label": "cat_co"
        },
        {
          "category": "USER_DEFINED",
          "typeId": 51,
          "label": null
        }
      ]
    }
  ]
}

 

If I misunderstood what you are trying to accomplish, please let me know.

 

Have fun building! — Jaycee

 

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Votes