• Stars
    star
    342
  • Rank 123,697 (Top 3 %)
  • Language
    PHP
  • License
    Other
  • Created about 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

HubSpot PHP API Client

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.โ€

This library supports only legacy API

Please consider switching to the latest API.

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 access token (OAuth2 or Private App)

$hubspot = SevenShores\Hubspot\Factory::createWithAccessToken('access-token');

// OR instantiate by passing a configuration array.
// The only required value is the 'key'
// Please note: as of November 30, 2022, HubSpot API Keys are being deprecated and are no longer supported.

$hubspot = new SevenShores\Hubspot\Factory([
    'key'      => 'demo',
    'oauth2'   => false, // default
]);

// Then you can call a resource 
// When referencing endpoints, use camelCase

$hubspot->contactlists

You can find more information about oauth2 access tokens here and about private app access token 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::createWithAccessToken())

$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' => 'access token',
    'oauth2' => true,
];

$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\Endpoints\Contacts;

$client = new Client(['key' => 'access token', 'oauth2' => true,]);

$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

More Repositories

1

youmightnotneedjquery

Astro
14,118
star
2

offline

Automatically display online/offline indication to your users
CSS
8,679
star
3

odometer

Smoothly transitions numbers with ease. #hubspot-open-source
CSS
7,259
star
4

vex

A modern dialog library which is highly configurable and easy to style. #hubspot-open-source
CSS
6,927
star
5

messenger

Growl-style alerts and messages for your app. #hubspot-open-source
JavaScript
4,024
star
6

drop

A library for creating dropdowns and other floating elements. #hubspot-open-source
CSS
2,360
star
7

BuckyClient

Collect performance data from the client
CoffeeScript
1,738
star
8

sortable

Drop-in script to make tables sortable
CSS
1,322
star
9

select

Styleable select elements built on Tether. #hubspot-open-source
JavaScript
1,197
star
10

humanize

A simple utility library for making the web more humane. #hubspot-open-source
JavaScript
907
star
11

Singularity

Scheduler (HTTP API and webapp) for running Mesos tasksโ€”long running processes, one-off tasks, and scheduled jobs. #hubspot-open-source
Java
816
star
12

tooltip

CSS Tooltips built on Tether. #hubspot-open-source
CSS
711
star
13

jinjava

Jinja template engine for Java
Java
687
star
14

signet

Display a unique seal in the developer console of your page
CoffeeScript
564
star
15

draft-convert

Extensibly serialize & deserialize Draft.js ContentState with HTML.
JavaScript
483
star
16

hubspot-api-python

HubSpot API Python Client Libraries for V3 version of the API
Python
323
star
17

cms-theme-boilerplate

A straight-forward starting point for building a great website on the HubSpot CMS
HTML
320
star
18

hubspot-api-nodejs

HubSpot API NodeJS Client Libraries for V3 version of the API
TypeScript
304
star
19

react-select-plus

Fork of https://github.com/JedWatson/react-select with option group support
JavaScript
281
star
20

SlimFast

Slimming down jars since 2016
Java
270
star
21

dropwizard-guice

Adds support for Guice to Dropwizard
Java
268
star
22

gc_log_visualizer

Generate multiple gnuplot graphs from java gc log data
Python
200
star
23

BuckyServer

Node server that receives metric data over HTTP & forwards to your service of choice
CoffeeScript
195
star
24

hubspot-api-php

HubSpot API PHP Client Libraries for V3 version of the API
PHP
191
star
25

general-store

Simple, flexible store implementation for Flux. #hubspot-open-source
JavaScript
173
star
26

hubspot-cli

A CLI for HubSpot
JavaScript
153
star
27

facewall

Grid visualization of Gravatars for an organization
CoffeeScript
138
star
28

jackson-datatype-protobuf

Java
116
star
29

draft-extend

Build extensible Draft.js editors with configurable plugins and integrated serialization.
JavaScript
116
star
30

prettier-maven-plugin

Java
116
star
31

slack-client

An asynchronous HTTP client for Slack's web API
Java
114
star
32

hubspot-api-ruby

HubSpot API Ruby Client Libraries for V3 version of the API
Ruby
113
star
33

Rosetta

Java library that leverages Jackson to take the pain out of mapping objects to/from the DB, designed to integrate seamlessly with jDBI
Java
110
star
34

Baragon

Load balancer API
Java
105
star
35

mixen

Combine Javascript classes on the fly
CoffeeScript
85
star
36

jquery-zoomer

Zoom up your iFrames
JavaScript
81
star
37

oauth-quickstart-nodejs

A Node JS app to get up and running with the HubSpot API using OAuth 2.0
JavaScript
79
star
38

hapipy

A Python wrapper for the HubSpot APIs #hubspot-open-source
Python
78
star
39

ui-extensions-examples

This repository contains code examples of UI extensions built with HubSpot CRM development tools beta
TypeScript
76
star
40

oneforty-data

Open data on 4,000+ social media apps from oneforty.com #hubspot-open-source
Ruby
70
star
41

cms-react-boilerplate

JavaScript
69
star
42

sample-workflow-custom-code

Sample code snippets for the custom code workflow action.
68
star
43

hubspot-cms-vscode

A HubL language extension for the Visual Studio Code IDE, allowing for ๐Ÿš€ fast local HubSpot CMS Platform development.
TypeScript
64
star
44

Blazar-Archive

An out-of-this world build system!
Java
62
star
45

haPiHP

An updated PHP client for the HubSpot API
PHP
61
star
46

sanetime

A sane date/time python interface #hubspot-open-source
Python
60
star
47

BidHub-CloudCode

The Parse-based brains behind BidHub, our open-source silent auction app.
JavaScript
50
star
48

teeble

A tiny table plugin
JavaScript
49
star
49

hubspot.github.com

HubSpot Open Source projects.
JavaScript
46
star
50

calling-extensions-sdk

A JavaScript SDK for integrating calling apps into HubSpot.
JavaScript
45
star
51

BidHub-iOS

iOS client for BidHub, our open-source silent auction app.
Objective-C
44
star
52

dropwizard-guicier

Java
42
star
53

hubspot-cms-deploy-action

GitHub Action to deploy HubSpot CMS projects
HTML
40
star
54

live-config

Live configuration for Java applications #hubspot-open-source
Java
37
star
55

executr

Let your users execute the CoffeeScript in your documentation
JavaScript
35
star
56

transmute

kind of like lodash but works with Immutable
JavaScript
35
star
57

NioImapClient

High performance, async IMAP client implementation
Java
34
star
58

colorshare

Style up your social share buttons
CSS
32
star
59

recruiting-agency-graphql-theme

A theme based off of the HubSpot CMS Boilerplate. This theme includes modules and templates that demonstrate how to utilize GraphQL as part of a website built with HubSpot CMS and Custom CRM Objects.
HTML
32
star
60

integration-examples-php

PHP
32
star
61

cms-event-registration

JavaScript
32
star
62

ChromeDevToolsClient

A java websocket client for the Chrome DevTools Protocol
Java
31
star
63

canvas

HubSpot Canvas is the design system that we at HubSpot use to build our products.
JavaScript
31
star
64

integration-examples-nodejs

JavaScript
31
star
65

cms-react

A repo to expose CMS react examples, React defaults modules, and more to CMS devs
JavaScript
30
star
66

sample-apps-list

The list of Sample applications using HubSpot Public API
28
star
67

NioSmtpClient

Smtp Client based on Netty
Java
28
star
68

vee

A personal proxy server for web developers
CoffeeScript
28
star
69

cms-js-building-block-examples

DEPRECATED, go to https://github.com/HubSpot/cms-react instead
JavaScript
28
star
70

prettier-plugin-hubl

HTML
25
star
71

jackson-jaxrs-propertyfiltering

Java
25
star
72

local-cms-server-cli

Command line tools for local cms development
CSS
22
star
73

astack

Simple stacktrace analysis tool for the JVM
Python
22
star
74

Horizon

Java
20
star
75

rHAPI

Ruby wrapper for the HubSpot API (HAPI)
Ruby
20
star
76

integrate

Confirm that your application works.
CoffeeScript
20
star
77

moxie

A TCP proxy guaranteed to make you smile. #hubspot-open-source
Python
18
star
78

BidHub-WebAdmin

Keep an eye on BidHub while it's doing its thing.
HTML
18
star
79

sample-apps-webhooks

Sample code and reference for processing HubSpot webhooks
JavaScript
17
star
80

hubspot-immutables

Java
17
star
81

cms-custom-objects-example

CSS
17
star
82

hubspot-academy-tutorials

JavaScript
17
star
83

hbase-support

Supporting configs and tools for HBase at HubSpot
Java
17
star
84

cms-vue-boilerplate

Boilerplate Vue project for creating apps using modules on the HubSpot CMS
JavaScript
17
star
85

sprocket

A better REST API framework for django
Python
17
star
86

sample-apps-manage-crm-objects

Sample application in PHP, Python, Ruby and JavaScript demonstrating HubSpot API to manage CRM Objects
JavaScript
17
star
87

react-decorate

Build composable, stateful decorators for React.
JavaScript
16
star
88

maven-snapshot-accelerator

System to speed up dependency resolution when using Maven snapshots #hubspot-open-source
Java
16
star
89

algebra

Simple abstract data types (wrapping derive4j) in Java
Java
15
star
90

sample-apps-oauth

Sample application demonstrating OAuth 2.0 flow with HubSpot API
Ruby
15
star
91

httpQL

A small library for converting URL query arguments into SQL queries.
Java
15
star
92

cms-webpack-serverless-boilerplate

Boilerplate for bundling serverless functions with webpack locally, prior to uploading to the CMS.
JavaScript
13
star
93

virtualenvchdir

Easily chdir into different virtualenvs #hubspot-open-source
Shell
12
star
94

HubspotEmailTemplate

How to convert a regular html coded email template into ones that use HubSpot jinja tags.
12
star
95

hubstar

CSS
12
star
96

private-app-starter

Boilerplates apps using HubSpot API
PHP
12
star
97

chrome_extension_workshop

Chrome extension workshop
JavaScript
11
star
98

serverless-function-examples

A collection of HubSpot related serverless functions examples.
JavaScript
11
star
99

cos_uploader

A python script for syncing a file tree to the HubSpot COS
Python
11
star
100

collectd-gcmetrics

Python
10
star