DEV Community

Cover image for The easiest way to use HubSpot Search API
Rutika Khaire
Rutika Khaire

Posted on

2

The easiest way to use HubSpot Search API

Whenever working on integrations, we basically use the APIs to retrieve the information. Some APIs are pretty straightforward to understand, so just by looking at the endpoint we can make out how to use it but sometimes, you need to dig in a bit to understand the usage.

I came across this situation in my application where I wanted to retrieve all the contacts from HubSpot based on a particular property value. For eg. If there is a contact property named Company_Affiliation and I want to retrieve all the contacts with a company affiliation value of say Fictional Company then how should I use the Search API?

The Endpoint

POST
/crm/v3/objects/contacts/search

The Input

const inputHubSpotSearchObject=
    {
        "objectName":"contacts",
        "limitValue":"100",
        "afterValue":"0",
        "filters":[
            {
                "value":req.body.company_name,
                "propertyName": "company_affiliation",
                "operator": "EQ"
            }

        ]
    }
Enter fullscreen mode Exit fullscreen mode

The API call

const response = await axios.post(`${process.env.API_URL}/api/hubspot/search`,inputHubSpotSearchObject,
                          {
                          headers: {
                              "Content-Type": "application/json",
                              Authorization: `Bearer ${accessToken}`,
                          }});
Enter fullscreen mode Exit fullscreen mode

The Response

Image description

Conclusion

I hope you found this article helpful. For more information visit link

Happy Coding!!!

API Trace View

Struggling with slow API calls? 👀

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay