Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time
March 10, 2022 12:23
December 22, 2022 17:09
December 22, 2022 17:09
February 15, 2022 17:53
February 15, 2022 17:48
January 12, 2023 17:01
April 21, 2020 17:08
January 12, 2023 16:59
November 21, 2022 12:12


Latest Packagist Version Total Downloads

PHP HubSpot API v3 SDK(Client) files


composer require hubspot/api-client


The current package requirements are:

PHP >= 7.3

Sample apps

Please, take a look at our Sample apps


To instantiate API Client using access token use Factory:

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

You'll need to create a private app to get your access token or you can obtain OAuth2 access token.

To instantiate API Client using developer apikey use Factory:

$hubspot = \HubSpot\Factory::createWithDeveloperApiKey('developer-apikey');

also you can pass custom client to Factory:

$client = new \GuzzleHttp\Client([...]);

$hubspot = \HubSpot\Factory::createWithAccessToken('access-token', $client);

To change the base path:

$config = new \GuzzleHttp\Config();

$hubspot = \HubSpot\Factory::create(null, $config);

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. Please note that Apps using OAuth are only subject to a limit of 100 requests every 10 seconds.

$handlerStack = \GuzzleHttp\HandlerStack::create();

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

$hubspot = \HubSpot\Factory::createWithAccessToken('access-token', $client);

Get contacts page:

$response = $hubspot->crm()->contacts()->basicApi()->getPage();

Search for a contact:

$filter = new \HubSpot\Client\Crm\Contacts\Model\Filter();

$filterGroup = new \HubSpot\Client\Crm\Contacts\Model\FilterGroup();

$searchRequest = new \HubSpot\Client\Crm\Contacts\Model\PublicObjectSearchRequest();

// Get specific properties
$searchRequest->setProperties(['firstname', 'lastname', 'date_of_birth', 'email']);

// @var CollectionResponseWithTotalSimplePublicObject $contactsPage
$contactsPage = $hubspot->crm()->contacts()->searchApi()->doSearch($searchRequest);

Create a contact:

$contactInput = new \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectInput();
    'email' => ''

$contact = $hubspot->crm()->contacts()->basicApi()->create($contactInput);

Update a contact:

$newProperties = new \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectInput();
    'email' => ''

$hubspot->crm()->contacts()->basicApi()->update($contactId, $newProperties);

Archive a contact:


Get custom objects page:


File uploading

$file = new \SplFileObject('file path');
$response = $hubspot->files()->filesApi()->upload($file, null, '/', null, null, json_encode([
    'access' => 'PRIVATE',
    'ttl' => 'P2W',
    'overwrite' => false,
    'duplicateValidationStrategy' => 'NONE',
    'duplicateValidationScope' => 'EXACT_FOLDER'
]) );

Not wrapped endpoint(s)

It is possible to access the hubspot request method directly, it could be handy if client doesn't have implementation for some endpoint yet. Exposed request method benefits by having all configured client params.

$response = $hubspot->apiRequest([
    'method' => 'PUT',
    'path' => '/some/api/not/wrapped/yet',
    'body' => ['key' => 'value'],

apiRequest options

    'method' => string, // Http method (e.g.: GET, POST, etc). Default value GET
    'path' => string, // URL path (e.g.: '/crm/v3/objects/contacts'). Optional
    'headers' => array, // Http headers. Optional.
    'body' => mixed, // Request body (if defaultJson set body will be transforted to json string).Optional.
    'authType' => enum(none, accessToken, hapikey), // Auth type. if it isn't set it will use accessToken or hapikey. Default value is non empty auth type.
    'baseUrl' => string, // Base URL. Default value ''.
    'qs' => array, // Query parameters. Optional.
    'defaultJson' => bool, // Default Json. if it is set to true it add to headers [ 'Content-Type' => 'application/json', 'Accept' => 'application/json, */*;q=0.8',]
    // and transfort body to json string. Default value true

get contacts

$response = $hubspot->apiRequest([
    'path' => '/crm/v3/objects/contacts',


Run spec tests

vendor/bin/phpspec run

Run unit tests

vendor/bin/phpunit ./tests