Connecting Laravel to the HubSpot CRM API: A Step‑by‑Step Guide for Seamless Customer Data Sync
Author: Dinesh Kumawat, Web Development Manager, D&D Technology
In today’s fast‑paced market, having a single source of truth for customer data is essential. HubSpot’s CRM provides a powerful platform for managing contacts, deals, and marketing automation, while Laravel offers a clean, expressive framework for building modern web applications. This tutorial walks you through the entire process of integrating HubSpot’s CRM API with a Laravel project, enabling automated contact management, lead capture, and workflow triggers—all without leaving your codebase.
Why Integrate HubSpot with Laravel?
- Unified data: Keep your website, SaaS product, or mobile backend in sync with HubSpot contacts and deals.
- Automation: Trigger HubSpot workflows directly from Laravel events (e.g., new user registration, order completion).
- Scalability: Leverage Laravel’s queue system for reliable, background API calls.
- Cost‑effective development: Reduce manual data entry and reliance on third‑party sync tools.
Prerequisites
Before we start, make sure you have the following:
- Laravel 9+ installed (we’ll use
php artisan servefor local testing). - Composer installed on your development machine.
- A HubSpot account with CRM API access and a private API key or OAuth token. For this guide we’ll use a private app token.
- Basic knowledge of REST APIs and Laravel service containers.
Step 1 – Create a New Laravel Project
composer create-project --prefer-dist laravel/laravel hubspot-integration
cd hubspot-integration
php artisan serve
Visit http://127.0.0.1:8000 to confirm the installation works.
Step 2 – Install the HubSpot PHP SDK
HubSpot maintains an official PHP client that simplifies authentication and request handling.
composer require hubspot/api-client
The SDK will be auto‑loaded via Composer.
Step 3 – Configure Environment Variables
Add your HubSpot private app token to the .env file. Never commit this file to version control.
HUBSPOT_API_TOKEN=your_private_app_token_here
Also, define a base URL for clarity (optional):
HUBSPOT_BASE_URL=https://api.hubapi.com
Step 4 – Create a Service Provider for HubSpot
Encapsulating the client in a service provider makes it easy to inject wherever needed.
php artisan make:provider HubSpotServiceProvider
Open app/Providers/HubSpotServiceProvider.php and update the register method:
public function register() { $this->app->singleton(\HubSpot\Client::class, function ($app) { return \HubSpot\Client::create() ->withAccessToken(env('HUBSPOT_API_TOKEN')); }); } public function boot() { // No boot logic needed for now }Was this article helpful? 4.8 (128 votes)
Join the Conversation
0 Comments