hubspot-php

HubSpot PHP API Client

Github stars Tracking Chart

HubSpot PHP API client

Version
Total Downloads
Build Status
License

Setup

Composer:

composer require "hubspot/hubspot-php"

Sample apps

Link

Quickstart

Examples Using Factory

All following examples assume this step.

$hubspot = SevenShores\Hubspot\Factory::create('api-key');

// OR create with OAuth2 access token

$hubspot = SevenShores\Hubspot\Factory::createWithOAuth2Token('access-token');

// OR instantiate by passing a configuration array.
// The only required value is the 'key'

$hubspot = new SevenShores\Hubspot\Factory([
  'key'      => 'demo',
  'oauth2'   => 'false', // default
]);

Note: You can prevent any error handling provided by this package by passing following options into client creation routine:
(applies also to Factory::create() and Factory::createWithOAuth2Token())

$hubspot = new SevenShores\Hubspot\Factory([
  'key'      => 'demo',
],
null,
[
  'http_errors' => false // pass any Guzzle related option to any request, e.g. throw no exceptions
],
false // return Guzzle Response object for any ->request(*) call
);

By setting http_errors to false, you will not receive any exceptions at all, but pure responses.
For possible options, see http://docs.guzzlephp.org/en/latest/request-options.html.

Get a single contact:

$contact = $hubspot->contacts()->getByEmail("test@hubspot.com");

echo $contact->properties->email->value;

Paginate through all contacts:

// Get an array of 10 contacts
// getting only the firstname and lastname properties
// and set the offset to 123456
$response = $hubspot->contacts()->all([
    'count'     => 10,
    'property'  => ['firstname', 'lastname'],
    'vidOffset' => 123456,
]);

Working with the data is easy!

foreach ($response->contacts as $contact) {
    echo sprintf(
        "Contact name is %s %s." . PHP_EOL,
        $contact->properties->firstname->value,
        $contact->properties->lastname->value
    );
}

// Info for pagination
echo $response->{'has-more'};
echo $response->{'vid-offset'};

or if you prefer to use array access?

foreach ($response['contacts'] as $contact) {
    echo sprintf(
        "Contact name is %s %s." . PHP_EOL,
        $contact['properties']['firstname']['value'],
        $contact['properties']['lastname']['value']
    );
}

// Info for pagination
echo $response['has-more'];
echo $response['vid-offset'];

Now with response methods implementing PSR-7 ResponseInterface

$response->getStatusCode()   // 200;
$response->getReasonPhrase() // 'OK';
// etc...

Example Without Factory

<?php

require 'vendor/autoload.php';

use SevenShores\Hubspot\Http\Client;
use SevenShores\Hubspot\Resources\Contacts;

$client = new Client(['key' => 'demo']);

$contacts = new Contacts($client);

$response = $contacts->all();

foreach ($response->contacts as $contact) {
    //
}

Example of using built in utils

<?php

require 'vendor/autoload.php';

use SevenShores\Hubspot\Utils\OAuth2;

$authUrl = OAuth2::getAuthUrl(
    'clientId',
    'http://localhost/callaback.php',
    'contacts'
);

or using Factory:

<?php

require 'vendor/autoload.php';

use SevenShores\Hubspot\Utils;

$authUrl = Utils::getFactory()->oAuth2()->getAuthUrl(
    'clientId',
    'http://localhost/callaback.php',
    'contacts'
);

Status

If you see something not planned, that you want, make an issue and there's a good chance I will add it.

  • Analytics API
  • Calendar API :upadated:
  • Companies API :upadated:
  • Company Properties API :upadated:
  • Contacts API :upadated:
  • Contact Lists API :upadated:
  • Contact Properties API :upadated:
  • Conversations Live Chat Widget API (Front End)
  • CMS Blog API (Blogs) :upadated:
  • CMS Blog Authors API (BlogAuthors) :upadated:
  • CMS Blog Comments API
  • CMS Blog Post API (BlogPosts)
  • CMS Blog Topics API (BlogTopics)
  • CMS Domains API
  • CMS Files API (Files)
  • CMS HubDB API (HubDB) :upadated:
  • CMS Layouts API
  • CMS Page Publishing API (Pages)
  • CMS Site Maps
  • CMS Site Search API
  • CMS Templates API
  • CMS URL Mappings API
  • CRM Associations API
  • CRM Extensions API
  • CRM Object Properties API (ObjectProperties) :new:
  • CRM Pipelines API (CrmPipelines)
  • Deals API
  • Deal Pipelines API :deprecated:
  • Deal Properties API :upadated:
  • Ecommerce Bridge API :upadated:
  • Email Subscription API :upadated:
  • Email Events API :upadated:
  • Engagements API
  • Events API
  • Forms API :upadated:
  • Line Items API :new:
  • Marketing Email API
  • Owners API :upadated:
  • Products API :new:
  • Social Media API
  • Tickets API
  • Timeline API :upadated:
  • Tracking Code API
  • Transactional Email API
  • Workflows API :upadated:
  • Webhooks API

Main metrics

Overview
Name With OwnerHubSpot/hubspot-php
Primary LanguagePHP
Program languagePHP (Language Count: 3)
Platform
License:Other
所有者活动
Created At2014-11-09 22:53:56
Pushed At2025-04-28 06:10:45
Last Commit At2025-04-25 15:22:37
Release Count61
Last Release Namev5.4.0 (Posted on )
First Release Namev0.1.0 (Posted on )
用户参与
Stargazers Count362
Watchers Count35
Fork Count197
Commits Count834
Has Issues Enabled
Issues Count157
Issue Open Count0
Pull Requests Count246
Pull Requests Open Count0
Pull Requests Close Count26
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private