hubspot_create_company
Create a new company record in HubSpot CRM to organize business contacts and track interactions.
Instructions
Create a new company in HubSpot
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Company name | |
| properties | No | Additional company properties |
Implementation Reference
- src/index.ts:249-260 (handler)MCP CallToolRequest handler case for 'hubspot_create_company' that extracts arguments and calls HubSpotClient.createCompanycase 'hubspot_create_company': { const result = await this.hubspot.createCompany( args.name as string, args.properties as Record<string, any> | undefined ); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }
- src/index.ts:106-123 (schema)Input schema definition for the hubspot_create_company tool, registered in ListTools response{ name: 'hubspot_create_company', description: 'Create a new company in HubSpot', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Company name' }, properties: { type: 'object', description: 'Additional company properties', additionalProperties: true } }, required: ['name'] }
- src/hubspot-client.ts:391-436 (helper)HubSpotClient.createCompany method implementing the core logic: checks for duplicates by name, creates company via HubSpot CRM API if new, with optional additional propertiesasync createCompany(name: string, properties?: Record<string, any>): Promise<any> { try { // Search for existing companies with same name // Use type assertion to satisfy the HubSpot API client types const searchRequest = { filterGroups: [{ filters: [ { propertyName: 'name', operator: 'EQ', value: name } as any ] }] } as any; const searchResponse = await this.client.crm.companies.searchApi.doSearch(searchRequest); if (searchResponse.total > 0) { // Company already exists return { message: 'Company already exists', company: searchResponse.results[0] }; } // If no existing company found, proceed with creation const companyProperties: Record<string, any> = { name }; // Add any additional properties if (properties) { Object.assign(companyProperties, properties); } // Create company const apiResponse = await this.client.crm.companies.basicApi.create({ properties: companyProperties }); return apiResponse; } catch (error: any) { console.error('Error creating company:', error); throw new Error(`HubSpot API error: ${error.message}`); }