2017 © Pedro PelĂĄez
 

library hubspot-php

HubSpot PHP API client

image

ryanwinchester/hubspot-php

HubSpot PHP API client

  • Friday, June 1, 2018
  • by ryanwinchester
  • Repository
  • 22 Watchers
  • 155 Stars
  • 269,105 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 95 Forks
  • 23 Open issues
  • 32 Versions
  • 16 % Grown

The README.md

HubSpot PHP API client

Version Total Downloads Build Status License, (*1)

Hubspot is a marketing, sales, and service software that helps your business grow without compromise. Because “good for the business” should also mean “good for the customer.”, (*2)

This library supports only legacy API

Please consider switching to the latest API., (*3)

Setup

Composer:, (*4)

composer require "hubspot/hubspot-php"

Sample apps

Link, (*5)

Quickstart

Examples Using Factory

All following examples assume this step., (*6)

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

// OR create with access token (OAuth2 or Private App)

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

// OR instantiate by passing a configuration array.
// The only required value is the 'key'
// Please note: as of November 30, 2022, HubSpot API Keys are being deprecated and are no longer supported.

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

// Then you can call a resource
// When referencing endpoints, use camelCase

$hubspot->contactlists

You can find more information about oauth2 access tokens here and about private app access token here., (*7)

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::createWithAccessToken()), (*8)

$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., (*9)

API Client comes with Middleware for implementation of Rate and Concurrent Limiting

It provides an ability to turn on retry for failed requests with statuses 429 or 500. You can read more about working within the HubSpot API rate limits here., (*10)

$handlerStack = \GuzzleHttp\HandlerStack::create();
$handlerStack->push(
    \SevenShores\Hubspot\RetryMiddlewareFactory::createRateLimitMiddleware(
        \SevenShores\Hubspot\Delay::getConstantDelayFunction()
    )
);

$handlerStack->push(
    \SevenShores\Hubspot\RetryMiddlewareFactory::createInternalErrorsMiddleware(
        \SevenShores\Hubspot\Delay::getExponentialDelayFunction(2)
    )
);

$guzzleClient = new \GuzzleHttp\Client(['handler' => $handlerStack]);

$config = [
    'key' => 'access token',
    'oauth2' => true,
];

$hubspot = new \SevenShores\Hubspot\Factory($config, new \SevenShores\Hubspot\Http\Client($config, $guzzleClient));

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!, (*11)

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?, (*12)

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, (*13)

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

Example Without Factory

<?php

require 'vendor/autoload.php';

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

$client = new Client(['key' => 'access token', 'oauth2' => true,]);

$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:, (*14)

<?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., (*15)

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

The Versions

01/06 2018

dev-master

9999999-dev

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

17/01 2018

v1.1.2

1.1.2.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

16/10 2017

2.0.x-dev

2.0.9999999.9999999-dev

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

16/10 2017

v1.1.1

1.1.1.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

08/08 2017

v1.1.0

1.1.0.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

16/05 2017

v1.0.4

1.0.4.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

19/02 2017

v1.0.3

1.0.3.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

10/02 2017

v1.0.2

1.0.2.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

25/01 2017

v1.0.1

1.0.1.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

18/01 2017

v1.0.0

1.0.0.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

18/10 2016

v1.0.0-rc.4

1.0.0.0-RC4

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

12/10 2016

v1.0.0-rc.3

1.0.0.0-RC3

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

10/06 2016

v1.0.0-rc.2

1.0.0.0-RC2

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

03/06 2016

v1.0.0-rc.1

1.0.0.0-RC1

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api hubspot

23/05 2016

v0.9.11

0.9.11.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

20/03 2016

v0.9.10

0.9.10.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

17/02 2016

dev-php54-guzzle5

dev-php54-guzzle5

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

28/12 2015

dev-php53

dev-php53

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

The Development Requires

by Ryan Winchester (fungku)
by Stuart Fyfe

api hubspot

17/10 2015

dev-develop

dev-develop

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

16/10 2015

v0.9.9

0.9.9.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

29/05 2015

v0.9.8

0.9.8.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

20/04 2015

v0.9.7

0.9.7.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

19/04 2015

v0.9.6

0.9.6.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

14/04 2015

v0.9.5

0.9.5.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

31/03 2015

v0.9.4

0.9.4.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

25/03 2015

v0.9.3

0.9.3.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

24/03 2015

v0.9.2

0.9.2.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

16/03 2015

v0.9.1

0.9.1.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

16/03 2015

v0.9

0.9.0.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

16/03 2015

v0.2

0.2.0.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Ryan Winchester (fungku)

api hubspot

15/11 2014

v0.1.1

0.1.1.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

by Ryan Winchester (fungku)

15/11 2014

v0.1.0

0.1.0.0

HubSpot PHP API client

  Sources   Download

Apache-2.0

The Requires

 

by Ryan Winchester (fungku)