hubspot-php

HubSpot PHP API Client

Github星跟蹤圖

HubSpot PHP API client

Version
Total Downloads
Build Status
License

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
]);

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.

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
  • 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) :new:
  • 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 :new:
  • Marketing Email API
  • Owners API :upadated:
  • Products API :new:
  • Social Media API
  • Tickets API
  • Timeline API :upadated:
  • Tracking Code API
  • Transactional Email API
  • Workflows API :upadated:
  • Webhooks API

主要指標

概覽
名稱與所有者HubSpot/hubspot-php
主編程語言PHP
編程語言PHP (語言數: 3)
平台
許可證Other
所有者活动
創建於2014-11-09 22:53:56
推送於2025-04-28 06:10:45
最后一次提交2025-04-25 15:22:37
發布數61
最新版本名稱v5.4.0 (發布於 )
第一版名稱v0.1.0 (發布於 )
用户参与
星數362
關注者數35
派生數197
提交數834
已啟用問題?
問題數157
打開的問題數0
拉請求數246
打開的拉請求數0
關閉的拉請求數26
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?