tschope / hubspot-php
HubSpot PHP API client
Requires
- php: >=7.0
- ext-json: *
- guzzlehttp/guzzle: ~6.0 | ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13
- phpspec/phpspec: ^6.2
- phpunit/phpunit: ~9.0
- dev-master
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.x-dev
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.3
- 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
This package is auto-updated.
Last update: 2024-10-16 21:02:17 UTC
README
Hubspot is a marketing, sales, and service software that helps your business grow without compromise. Because “good for the business” should also mean “good for the customer.”
Setup
Composer:
composer require "hubspot/hubspot-php"
Sample apps
Quickstart
Examples Using Factory
All following examples assume this step.
$hubspot = SevenShores\Hubspot\Factory::create('api-key'); // OR create with OAuth2 access token $hubspot = SevenShores\Hubspot\Factory::createWithOAuth2Token('access-token'); // OR instantiate by passing a configuration array. // The only required value is the 'key' $hubspot = new SevenShores\Hubspot\Factory([ 'key' => 'demo', 'oauth2' => 'false', // default ]);
You can find more information about API keys here and about access tokens here
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::createWithOAuth2Token()
)
$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 );
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.
API Client comes with Middleware for implementation of Rate and Concurrent Limiting.
It provides an ability to turn on retry for failed requests with statuses 429 or 500. You can read more about working within the HubSpot API rate limits here.
$handlerStack = \GuzzleHttp\HandlerStack::create(); $handlerStack->push( \SevenShores\Hubspot\RetryMiddlewareFactory::createRateLimitMiddleware( \SevenShores\Hubspot\Delay::getConstantDelayFunction() ) ); $handlerStack->push( \SevenShores\Hubspot\RetryMiddlewareFactory::createInternalErrorsMiddleware( \SevenShores\Hubspot\Delay::getExponentialDelayFunction(2) ) ); $guzzleClient = new \GuzzleHttp\Client(['handler' => $handlerStack]); $config = [ 'key' => 'demo', 'oauth2' => false, ]; $hubspot = new \SevenShores\Hubspot\Factory(config, new \SevenShores\Hubspot\Http\Client($config, guzzleClient));
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) { // }
Example of using built in utils
<?php require 'vendor/autoload.php'; use SevenShores\Hubspot\Utils\OAuth2; $authUrl = OAuth2::getAuthUrl( 'clientId', 'http://localhost/callaback.php', 'contacts' );
or using Factory:
<?php require 'vendor/autoload.php'; use SevenShores\Hubspot\Utils; $authUrl = Utils::getFactory()->oAuth2()->getAuthUrl( 'clientId', 'http://localhost/callaback.php', 'contacts' );
Status
If you see something not planned, that you want, make an issue and there's a good chance I will add it.
- Analytics API
- Calendar API :upadated:
- Companies API :upadated:
- Company Properties API :upadated:
- Contacts API :upadated:
- Contact Lists API :upadated:
- Contact Properties API :upadated:
- Conversations Live Chat Widget API (Front End)
- CMS Blog API (Blogs) :upadated:
- CMS Blog Authors API (BlogAuthors) :upadated:
- CMS Blog Comments API (Comments)
- CMS Blog Post API (BlogPosts)
- CMS Blog Topics API (BlogTopics)
- CMS Domains API
- CMS Files API (Files)
- CMS HubDB API (HubDB) :upadated:
- CMS Layouts API
- CMS Page Publishing API (Pages)
- CMS Site Maps
- CMS Site Search API
- CMS Templates API
- CMS URL Mappings API
- CRM Associations API
- CRM Extensions API
- CRM Object Properties API (ObjectProperties) 🆕
- CRM Pipelines API (CrmPipelines)
- Deals API
- Deal Pipelines API :deprecated:
- Deal Properties API :upadated:
- Ecommerce Bridge API :upadated:
- Email Subscription API :upadated:
- Email Events API :upadated:
- Engagements API
- Events API
- Forms API :upadated:
- Line Items API 🆕
- Marketing Email API
- Owners API :upadated:
- Products API 🆕
- Social Media API
- Tickets API
- Timeline API :upadated:
- Tracking Code API
- Transactional Email API
- Workflows API :upadated:
- Webhooks API