arcade-mcp/toolkits/hubspot/arcade_hubspot/tools/crm/companies.py
Renato Byrro de227c5f51
Hubspot toolkit (#363)
Reviewer:

1. DM me to get a client ID/secret for the Hubspot app and login
credentials for a sample Hubspot account
2. For now, you'll need to run the engine on the branch
`nate/token-introspection` for the auth flow to work with Hubspot
3. Add the following to `auth.providers` in your engine yaml:

```yaml
- id: arcade-hubspot
  description: 'Hubspot provider'
  enabled: true
  type: oauth2
  provider_id: hubspot
  client_id: ${env:HUBSPOT_CLIENT_ID}
  client_secret: ${env:HUBSPOT_CLIENT_SECRET}
```
2025-04-22 17:43:15 -03:00

63 lines
1.9 KiB
Python

from typing import Annotated, Any, Optional
from arcade.sdk import ToolContext, tool
from arcade.sdk.auth import OAuth2
from arcade_hubspot.enums import HubspotObject
from arcade_hubspot.models import HubspotCrmClient
@tool(
requires_auth=OAuth2(
id="hubspot",
scopes=[
"oauth",
"crm.objects.companies.read",
"crm.objects.contacts.read",
"crm.objects.deals.read",
"sales-email-read",
],
),
)
async def get_company_data_by_keywords(
context: ToolContext,
keywords: Annotated[
str,
"The keywords to search for companies. It will match against the company name, phone, "
"and website.",
],
limit: Annotated[
int, "The maximum number of companies to return. Defaults to 10. Max is 10."
] = 10,
next_page_token: Annotated[
Optional[str],
"The token to get the next page of results. "
"Defaults to None (returns first page of results)",
] = None,
) -> Annotated[
dict[str, Any],
"Retrieve company data with associated contacts, deals, calls, emails, "
"meetings, notes, and tasks.",
]:
"""Retrieve company data with associated contacts, deals, calls, emails,
meetings, notes, and tasks.
This tool will return up to 10 items of each associated object (contacts, leads, etc).
"""
limit = min(limit, 10)
client = HubspotCrmClient(context.get_auth_token_or_empty())
return await client.search_by_keywords(
object_type=HubspotObject.COMPANY,
keywords=keywords,
limit=limit,
next_page_token=next_page_token,
associations=[
HubspotObject.CALL,
HubspotObject.CONTACT,
HubspotObject.DEAL,
HubspotObject.EMAIL,
HubspotObject.MEETING,
HubspotObject.NOTE,
HubspotObject.TASK,
],
)