felixmaier1989 / hubspot-php
HubSpot PHP API client
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master@dev
- phpspec/phpspec: ~2.0
- phpunit/phpunit: ~4.0
- dev-master
- 2.0.x-dev
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v1.0.0-rc.4
- v1.0.0-rc.3
- v1.0.0-rc.2
- v1.0.0-rc.1
- v0.9.11
- v0.9.10
- v0.9.9
- v0.9.8
- v0.9.7
- v0.9.6
- v0.9.5
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9
- v0.2
- v0.1.1
- v0.1.0
- dev-daily-api-usage
- dev-update-companies-batch
- dev-php54-guzzle5
- dev-php53
- dev-develop
This package is auto-updated.
Last update: 2024-12-04 21:10:35 UTC
README
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.
Setup
Composer:
composer require "ryanwinchester/hubspot-php:~1.0"
Quickstart
Examples Using Factory
All following examples assume this step.
$hubspot = SevenShores\Hubspot\Factory::create('api-key'); // OR instantiate by passing a configuration array. // The only required value is the 'key' $hubspot = new SevenShores\Hubspot\Factory([ 'key' => 'demo', 'oauth' => false, // default 'base_url' => 'https://api.hubapi.com' // default ]);
Note: You can prevent any error handling provided by this package by passing following options into client creation routine:
(applies also to Factory::create()
and Factory::createWithToken()
)
$hubspot = new SevenShores\Hubspot\Factory([ 'key' => 'demo', 'oauth' => false, // default 'base_url' => 'https://api.hubapi.com' // default ], 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 );
By setting http_errors
to false, you will not receive any exceptions at all, but pure responses.
For possible options, see http://docs.guzzlephp.org/en/latest/request-options.html.
Get a single contact:
$contact = $hubspot->contacts()->getByEmail("test@hubspot.com"); echo $contact->properties->email->value;
Paginate through all contacts:
// 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...
Example Without Factory
<?php require 'vendor/autoload.php'; use SevenShores\Hubspot\Http\Client; use SevenShores\Hubspot\Resources\Contacts; $client = new Client(['key' => 'demo']); $contacts = new Contacts($client); $response = $contacts->all(); foreach ($response->contacts as $contact) { // }
Status
If you see something not planned, that you want, make an issue and there's a good chance I will add it.
- Blogs (COS) 🆕
- Blog Authors (COS) 🆕
- Blog Posts (COS) 🆕
- Blog Topics (COS) 🆕
- Companies 🆕
- Company Properties 🆕
- Contacts
- Contact Lists
- Contact Properties
- Deals 🆕
- Email 🆕
- Email Events 🆕
- Engagements
- Events (Enterprise) 🆕
- Files (COS) 🆕
- Forms
- Keywords
- Owners
- Page Publishing (COS) 🆕
- Social Media
- Templates (COS) 🆕
- Timeline 🆕
- Workflows