GithubHelp home page GithubHelp logo

hubspot-php's Introduction

HubSpot PHP API client

Version Total Downloads Build Status License

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

Link

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("[email protected]");

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 :updated:
  • Companies API :updated:
  • Company Properties API :updated:
  • Contacts API :updated:
  • Contact Lists API :updated:
  • Contact Properties API :updated:
  • Conversations Live Chat Widget API (Front End)
  • CMS Blog API (Blogs) :updated:
  • CMS Blog Authors API (BlogAuthors) :updated:
  • CMS Blog Comments API (BlogComments)
  • CMS Blog Post API (BlogPosts)
  • CMS Blog Topics API (BlogTopics)
  • CMS Domains API
  • CMS Files API (Files)
  • CMS HubDB API (HubDB) :updated:
  • 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 :updated:
  • Ecommerce Bridge API :updated:
  • Email Subscription API :updated:
  • Email Events API :updated:
  • Engagements API
  • Events API
  • Forms API :updated:
  • Line Items API 🆕
  • Marketing Email API
  • Owners API :updated:
  • Products API 🆕
  • Social Media API
  • Tickets API
  • Timeline API :updated:
  • Tracking Code API
  • Transactional Email API
  • Workflows API :updated:
  • Webhooks API

hubspot-php's People

Contributors

aditya-mfs avatar amyboyd avatar atanasiuk-hubspot avatar atymic avatar carcus88 avatar cincauhangus avatar denniskorbginski avatar domagoj03 avatar erikrorstrom avatar felixmaier1989 avatar ffauvel avatar fyfey avatar geekdevs avatar graymouser avatar iillexial avatar jamesgraham avatar joesantos418 avatar johncongdon avatar ksvirkou-hubspot avatar lordthorzonus avatar lukevers avatar maddy2101 avatar massimilianobraglia avatar morrislaptop avatar nediam avatar nicobraintly avatar ryanwinchester avatar siremi avatar thunder87 avatar yfaktor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.