PHP code example of swithfr / api-client

1. Go to this page and download the library: Download swithfr/api-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

swithfr / api-client example snippets


$hubSpot = \HubSpot\Factory::createWithApiKey('api-key');

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

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

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

$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($_POST);

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

$newProperties = new \HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectInput();
$newProperties->setProperties($_POST);

$hubSpot->crm()->contacts()->basicApi()->update($contactId, $newProperties);
 
$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”
]) );