1. Go to this page and download the library: Download ryanwinchester/hubspot-php 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/ */
ryanwinchester / hubspot-php example snippets
$hubspot = SevenShores\Hubspot\Factory::create('api-key');
// OR create with access token (OAuth2 or Private App)
$hubspot = SevenShores\Hubspot\Factory::createWithAccessToken('access-token');
// OR instantiate by passing a configuration array.
// The only n referencing endpoints, use camelCase
$hubspot->contactlists
$hubspot = new SevenShores\Hubspot\Factory(
[
'key' => 'demo',
],
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
);
// 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,
]);
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'};
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'];