A new HubSpot API client. The sequel to my perfectly functional wrapper of HubSpot/haPihP. client. However, this is a complete re-write and includes some of the new COS/v2 endpoints.
Please try it out, and let me know if things are working as expected. There may still be a few small breaking changes here and there, so it is not recommended to use this in production unless you really know what you're doing and don't mind working with code that is changing...
I've upgraded to Guzzle v6 now.
- For php 5.3: see the php53 branch. You will need to supply your own
HttpClient
implementation. - For php 5.4: see the php54-guzzle5 branch.
Composer:
composer require "fungku/hubspot-php: dev-master"
All following examples assume this step.
Note: The HubSpot class checks for a HUBSPOT_API_KEY
environment variable if you don't include one during instantiation.
$hubspot = Fungku\HubSpot\HubSpotService::make('api-key');
$contact = $hubspot->contacts()->getByEmail("test@hubspot.com");
echo $contact->properties->email->value;
// 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,
]);
Working with the data is easy!
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'};
or if you prefer to use array access?
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'];
Now with response methods implementing PSR-7 ResponseInterface
$response->getStatusCode() // 200;
$response->getReasonPhrase() // 'OK';
// etc...
If you see something not planned, that you want, make an issue and there's a good chance I will add it.
- Blog (COS) 🆕
- Blog Posts (COS) 🆕
- Blog Topics (COS) 🆕
- Companies 🆕
- Company Properties 🆕
- Contacts
- Contact Lists
- Contact Properties
- Deals 🆕
- Email 🆕
- Email Events 🆕
- Events (Enterprise) 🆕
- Files (COS) 🆕
- Forms
- Keywords
- Page Publishing (COS) 🆕
- Social Media
- Templates (COS) 🆕
- Workflows