hubspot / api-client
Hubspot API client
Requires
- php: >=8.1
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^7.3
- guzzlehttp/psr7: ^1.7 || ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- phpspec/phpspec: ^8.2
- phpunit/phpunit: ^11.5
- dev-master
- 14.1.0
- 14.0.7
- 14.0.6
- 14.0.5
- 14.0.4
- 14.0.3
- 14.0.2
- 14.0.1
- 14.0.0
- 13.2.0
- 13.1.1
- 13.1.0
- 13.0.1
- 13.0.0
- 13.0.0beta.1
- 12.2.0
- 12.1.0
- 12.0.0
- 11.3.0
- 11.2.0
- 11.1.0
- 11.0.0
- 10.3.0
- 10.2.0
- 10.1.2
- 10.1.1
- 10.1.0
- 10.0.1
- 10.0.0
- 10.0.0-beta.3
- 10.0.0-beta.2
- 10.0.0-beta
- 9.4.0
- 9.3.0
- 9.2.2
- 9.2.1
- 9.2.0
- 9.1.0
- 9.0.1
- 9.0.0
- 8.4.1
- 8.4.0
- 8.3.1
- 8.3.0
- 8.2.1
- 8.2.0
- 8.1.2
- 8.1.1
- 8.1.0
- 8.0.0
- 7.0.0
- 6.0.1
- 6.0.0
- 5.1.1
- 5.1.0
- 5.0.0
- v4.x-dev
- 4.0.0
- 3.1.0
- 3.0.2
- 3.0.1
- 2.8.1
- 2.8.0
- 2.7.1
- 2.7.0
- 2.6.1
- 2.6.0
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- v1.x-dev
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.0-beta
- dev-feature/14.0.4
- dev-codegen/crmDeals
- dev-feature/15.0.0
This package is auto-updated.
Last update: 2026-05-12 06:33:44 UTC
README
PHP HubSpot API v3 SDK(Client) files
Installation
composer require hubspot/api-client
Requirements
The current package requirements are:
PHP >= 8.1
Sample apps
Please, take a look at our Sample apps
Quickstart
To instantiate API Client using access token use Factory
$hubspot = \HubSpot\Factory::createWithAccessToken('your-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('your-developer-apikey');
also you can pass custom client to Factory
$client = new \GuzzleHttp\Client([...]); $hubspot = \HubSpot\Factory::createWithAccessToken('your-access-token', $client);
To change the base path
$config = new \GuzzleHttp\Client(); $config->setBasePath('*'); $config->setAccessToken('*'); $config->setDeveloperApiKey('*'); $hubspot = \HubSpot\Factory::create(null, $config);
Retry Middleware
The API client provides retry middleware for three failure scenarios: rate limiting (429), internal server errors (500–503, 520–599), and connection errors. All middleware retry up to RetryMiddlewareFactory::DEFAULT_MAX_RETRIES (5) times by default.
If no delay function is provided, Guzzle applies its built-in exponential backoff. Available delay helpers:
Delay::getConstantDelayFunction(int $secondsDelay = 10)— fixed delay between retriesDelay::getLinearDelayFunction()— delay grows linearly with retry count
Please note that Apps using OAuth are only subject to a limit of 100 requests every 10 seconds.
$handlerStack = \GuzzleHttp\HandlerStack::create(); // Retry on 429 with a constant 10-second delay $handlerStack->push( \HubSpot\RetryMiddlewareFactory::createRateLimitMiddleware( \HubSpot\Delay::getConstantDelayFunction() ) ); // Retry on 5xx errors (exponential backoff by default) $handlerStack->push( \HubSpot\RetryMiddlewareFactory::createInternalErrorsMiddleware() ); // Retry on connection errors for cURL codes 52, 55, 56 (exponential backoff by default) // Pass an empty array to retry all ConnectExceptions regardless of cURL error code $handlerStack->push( \HubSpot\RetryMiddlewareFactory::createConnectionErrorsMiddleware() ); $client = new \GuzzleHttp\Client(['handler' => $handlerStack]); $hubspot = \HubSpot\Factory::createWithAccessToken('your-access-token', $client);
Get contacts page
$response = $hubspot->crm()->contacts()->basicApi()->getPage();
Get contact by email
$contact = $hubSpot->crm()->contacts()->basicApi()->getById('example@example.com', null, null, null, false, 'email');
Search for a contact
$filter = new \HubSpot\Client\Crm\Contacts\Model\Filter(); $filter ->setOperator('EQ') ->setPropertyName('email') ->setValue($search); $filterGroup = new \HubSpot\Client\Crm\Contacts\Model\FilterGroup(); $filterGroup->setFilters([$filter]); $searchRequest = new \HubSpot\Client\Crm\Contacts\Model\PublicObjectSearchRequest(); $searchRequest->setFilterGroups([$filterGroup]); // 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(); $contactInput->setProperties([ 'email' => 'example@example.com' ]); $contact = $hubspot->crm()->contacts()->basicApi()->create($contactInput);
Update a contact
$newProperties = new \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectInput(); $newProperties->setProperties([ 'email' => 'updatedExample@example.com' ]); $hubspot->crm()->contacts()->basicApi()->update($contactId, $newProperties);
Archive a contact
$hubspot->crm()->contacts()->basicApi()->archive($contactId);
Get custom objects page
$hubspot->crm()->objects()->basicApi()->getPage($objectType)
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, developerApiKey), // 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 'https://api.hubapi.com'.
'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', ]);
Reserved words
The SDK has reserved words(e.g. clone). Full list of reserved words.
When you face with a reserved word you have to add _ before the word(e.g. _clone).
Contributing
Run spec tests
vendor/bin/phpspec run
Run unit tests
vendor/bin/phpunit ./tests