PHPackages                             fungku/hubspot-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. fungku/hubspot-php

Abandoned → [ryanwinchester/hubspot-php](/?search=ryanwinchester%2Fhubspot-php)Library[API Development](/categories/api)

fungku/hubspot-php
==================

HubSpot PHP API client

4.0.1(4y ago)30346.9k193[3 issues](https://github.com/ryanwinchester/hubspot-php/issues)1Apache-2.0PHPPHP &gt;=7.3

Since Nov 15Pushed 10mo ago33 watchersCompare

[ Source](https://github.com/ryanwinchester/hubspot-php)[ Packagist](https://packagist.org/packages/fungku/hubspot-php)[ RSS](/packages/fungku-hubspot-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (59)Used By (1)

HubSpot PHP API client
======================

[](#hubspot-php-api-client)

[![Version](https://camo.githubusercontent.com/d39146194f0e577e7358b495d8187fe7bfc0c85846d796f0ecb7ce5b56991243/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68756273706f742f68756273706f742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hubspot/hubspot-php)[![Total Downloads](https://camo.githubusercontent.com/f88bae3d88f055d81e76ba07fbf6160cab4a5715459c0373268079f499d79f68/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68756273706f742f68756273706f742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hubspot/hubspot-php)[![Build Status](https://camo.githubusercontent.com/0d8a54c4853da0d1b38829dca7131800a99a95b85590e5d2800342024f54afd9/68747470733a2f2f7472617669732d63692e6f72672f68756273706f742f68756273706f742d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/hubspot/hubspot-php)[![License](https://camo.githubusercontent.com/7d93a50f40c4c133482d4cceb11d212aff069b68391cfddb26751016c1f807d3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f68756273706f742f68756273706f742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hubspot/hubspot-php)

[Hubspot](https://www.hubspot.com/) 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.”

This library supports only [legacy API](https://legacydocs.hubspot.com/docs/overview)
-------------------------------------------------------------------------------------

[](#this-library-supports-only-legacy-api)

Please consider switching to [the latest API](https://github.com/HubSpot/hubspot-api-php).

Setup
-----

[](#setup)

**Composer:**

```
composer require "hubspot/hubspot-php"
```

Sample apps
-----------

[](#sample-apps)

[Link](https://github.com/HubSpot/integration-examples-php)

Quickstart
----------

[](#quickstart)

### Examples Using Factory

[](#examples-using-factory)

All following examples assume this step.

```
$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](https://developers.hubspot.com/docs/api/oauth/tokens) and about private app access token [here](https://developers.hubspot.com/docs/api/private-apps).

*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()`)

```
$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 .

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

[](#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](https://developers.hubspot.com/docs/faq/working-within-the-hubspot-api-rate-limits).

```
$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

[](#get-a-single-contact)

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

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

#### Paginate through all contacts

[](#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](https://github.com/php-fig/http-message/tree/master/src)

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

### Example Without Factory

[](#example-without-factory)

```
