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

ActiveLibrary[API Development](/categories/api)

felixmaier1989/hubspot-php
==========================

HubSpot PHP API client

v1.1.2(8y ago)024.2k1Apache-2.0PHPPHP &gt;=5.5.0

Since Nov 15Pushed 8y ago1 watchersCompare

[ Source](https://github.com/felixmaier1989/hubspot-php)[ Packagist](https://packagist.org/packages/felixmaier1989/hubspot-php)[ RSS](/packages/felixmaier1989-hubspot-php/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (34)Used By (0)

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

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

[![Version](https://camo.githubusercontent.com/9d4e1b3a80862e708f283b44081e42d3d228da4524dff8536716f3fb693e98e1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7279616e77696e636865737465722f68756273706f742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ryanwinchester/hubspot-php)[![Total Downloads](https://camo.githubusercontent.com/1b24bd429ab2e2e8fe706ca4e2c756f2b189b6430ba5b7e5d47c625b7eb41adf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7279616e77696e636865737465722f68756273706f742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ryanwinchester/hubspot-php)[![License](https://camo.githubusercontent.com/9c6689e600fd8666044d4177a7510570db7b5c76760f31c1172e65d02701ba83/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7279616e77696e636865737465722f68756273706f742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ryanwinchester/hubspot-php)

Hubspot API client. The sequel to my [perfectly functional wrapper](https://github.com/fungku/hubspot) of HubSpot/haPihP. client. However, this is a complete re-write and includes some of the new COS/v2 endpoints.

Setup
-----

[](#setup)

**Composer:**

```
composer require "ryanwinchester/hubspot-php:~1.0"
```

Quickstart
----------

[](#quickstart)

### Examples Using Factory

[](#examples-using-factory)

All following examples assume this step.

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

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

$hubspot = new SevenShores\Hubspot\Factory([
  'key'      => 'demo',
  'oauth'    => false, // default
  'base_url' => 'https://api.hubapi.com' // 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::createWithToken()`)

```
$hubspot = new SevenShores\Hubspot\Factory([
  'key'      => 'demo',
  'oauth'    => false, // default
  'base_url' => 'https://api.hubapi.com' // default
],
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 .

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

```
