Skip to content

How to Create a HubSpot App Using Laravel

November 5, 2025 · admin

Integrating HubSpot with Laravel gives you the best of both worlds —
a powerful CRM and marketing automation platform combined with a robust PHP framework that’s ideal for custom web apps.
In this guide, we’ll walk you through how to build a HubSpot app using Laravel from scratch,
connect APIs, and automate your marketing workflows.


Why Use Laravel to Build a HubSpot App?

Laravel provides a clean and elegant syntax, built-in API resources, authentication scaffolding, and queue management —
making it perfect for integrating with third-party APIs like HubSpot’s CRM and Marketing APIs.

  • ✔️ Easy integration with REST APIs and webhooks
  • ✔️ Built-in HTTP client (via Http::) for handling HubSpot requests
  • ✔️ Secure OAuth authentication for HubSpot Apps
  • ✔️ Perfect structure for scalable CRM-driven applications

Step 1: Create a HubSpot Developer Account

To start, create a free developer account at
developers.hubspot.com.
Once inside, click on “Create App”. You’ll be prompted to enter basic app details such as:

  • App Name and Description
  • Redirect URL (this is your Laravel callback URL)
  • OAuth Scopes (for CRM, Contacts, Deals, or Marketing)

Example Redirect URL:
https://yourdomain.com/hubspot/callback


Step 2: Set Up a New Laravel Project

Install Laravel using Composer:

composer create-project laravel/laravel hubspot-app

Then, add your environment variables for HubSpot OAuth:


HUBSPOT_CLIENT_ID=your-client-id
HUBSPOT_CLIENT_SECRET=your-client-secret
HUBSPOT_REDIRECT_URI=https://yourdomain.com/hubspot/callback

Step 3: Create the OAuth Flow in Laravel

In your routes file (web.php), define routes for authorization and callback:


Route::get('/hubspot/connect', [HubspotController::class, 'connect']);
Route::get('/hubspot/callback', [HubspotController::class, 'callback']);

Then, inside HubspotController.php:


use Illuminate\Support\Facades\Http;

class HubspotController extends Controller
{
    public function connect()
    {
        $query = http_build_query([
            'client_id' => env('HUBSPOT_CLIENT_ID'),
            'redirect_uri' => env('HUBSPOT_REDIRECT_URI'),
            'scope' => 'contacts',
            'response_type' => 'code',
        ]);
        return redirect('https://app.hubspot.com/oauth/authorize?' . $query);
    }

    public function callback(Request $request)
    {
        $response = Http::asForm()->post('https://api.hubapi.com/oauth/v1/token', [
            'grant_type' => 'authorization_code',
            'client_id' => env('HUBSPOT_CLIENT_ID'),
            'client_secret' => env('HUBSPOT_CLIENT_SECRET'),
            'redirect_uri' => env('HUBSPOT_REDIRECT_URI'),
            'code' => $request->code,
        ]);

        $tokens = $response->json();
        // Save tokens in your DB for future API calls
        return response()->json($tokens);
    }
}

Once authorized, you’ll get access and refresh tokens.
You can now make authenticated API calls to HubSpot.


Step 4: Fetch and Manage HubSpot Data

Use the tokens from your OAuth flow to interact with HubSpot’s CRM.
For example, to fetch contacts:


$response = Http::withToken($access_token)
    ->get('https://api.hubapi.com/crm/v3/objects/contacts');

$contacts = $response->json();

You can then display or sync this data inside your Laravel app for lead management, analytics, or automation.


Step 5: Automate Workflows and Webhooks

Once your app is connected, set up webhooks in HubSpot to trigger Laravel events when contacts are created,
deals are updated, or emails are opened.
Laravel’s queue and event system make it easy to process these in the background.

Example webhook endpoint:


Route::post('/hubspot/webhook', [HubspotWebhookController::class, 'handle']);

Best Practices for SEO and Performance

  • ⚙️ Use queues to handle heavy API requests asynchronously.
  • 🧠 Cache frequently accessed data (e.g., contact lists).
  • 🔐 Refresh tokens periodically to keep access valid.
  • 💡 Use Laravel’s built-in logging for API debugging.
  • 📈 Track HubSpot API events in your analytics dashboard.

Conclusion

Building a HubSpot App using Laravel gives you the flexibility to automate marketing tasks,
synchronize CRM data, and deliver seamless customer experiences.
With just a few lines of code, you can connect both platforms and open endless possibilities for your business.

Need Help? Hire Our Laravel Experts


Tags:

#HubSpot #Laravel #CRMIntegration #APIDevelopment #TrijalsoftSolutions

❓ Frequently Asked Questions

Yes. You can integrate HubSpot APIs into any existing Laravel project by adding the OAuth flow, access tokens, and CRM API endpoints. No need to rebuild your application.

No, you can use a free HubSpot developer account to build and test your app before deploying it for production use.

Very secure. Laravel uses CSRF protection, encrypted environment variables, and HTTPS callbacks to ensure your OAuth flow is safe and compliant.

Absolutely. You can use HubSpot webhooks to trigger Laravel events when leads are added, deals are updated, or marketing emails are opened.