PHPackages                             sharefaithdev/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. sharefaithdev/hubspot-php

AbandonedArchivedLibrary[API Development](/categories/api)

sharefaithdev/hubspot-php
=========================

HubSpot PHP API client

v2.0.6(5y ago)06Apache-2.0PHPPHP &gt;=7.0

Since Nov 15Pushed 5y agoCompare

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

READMEChangelog (1)Dependencies (4)Versions (47)Used By (0)

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.”

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 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
]);
```

You can find more information about API keys [here](https://knowledge.hubspot.com/integrations/how-do-i-get-my-hubspot-api-key) and about access tokens [here](https://developers.hubspot.com/docs/api/oauth/tokens)

*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 .

#### 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'      => 'demo',
    'oauth2'   => false,
];

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

```
