PHP HubSpot API v3 SDK(Client) files
composer require hubspot/api-client
Please, take a look at our Sample apps
$hubSpot = \HubSpot\Factory::createWithApiKey('api-key');
$hubSpot = \HubSpot\Factory::createWithAccessToken('access-token');
$client = new \GuzzleHttp\Client([...]);
$hubSpot = \HubSpot\Factory::createWithAccessToken('access-token', $client);
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();
$handlerStack->push(
\HubSpot\RetryMiddlewareFactory::createRateLimitMiddleware(
\HubSpot\Delay::getConstantDelayFunction()
)
);
$handlerStack->push(
\HubSpot\RetryMiddlewareFactory::createInternalErrorsMiddleware(
\HubSpot\Delay::getExponentialDelayFunction(2)
)
);
$client = new \GuzzleHttp\Client(['handler' => $handlerStack]);
$hubSpot = \HubSpot\Factory::createWithAccessToken('access-token', $client);
$response = $hubSpot->crm()->contacts()->basicApi()->getPage();
$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]);
// @var CollectionResponseWithTotalSimplePublicObject $contactsPage
$contactsPage = $hubSpot->crm()->contacts()->searchApi()->doSearch($searchRequest);
$contactInput = new \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectInput();
$contactInput->setProperties([
'email' => 'example@example.com'
]);
$contact = $hubSpot->crm()->contacts()->basicApi()->create($contactInput);
$newProperties = new \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectInput();
$newProperties->setProperties([
'email' => 'updatedExample@example.com'
]);
$hubSpot->crm()->contacts()->basicApi()->update($contactId, $newProperties);
$hubSpot->crm()->contacts()->basicApi()->archive($contactId);
$hubSpot->crm()->objects()->basicApi()->getPage(HubSpot\Crm\ObjectType::CONTACTS)
$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”
]) );
vendor/bin/phpspec run
vendor/bin/phpunit ./tests