hubspot-php

HubSpot长期未更新

HubSpot 官方 PHP 客户端,封装 CRM 等 REST API 的鉴权、请求与响应处理,省去手写 HTTP 调用。

HubSpot PHP API Client

v5.5.0发布于 2025-06-26 14:45 UTC368star194fork同步于 2026-11-07 07:32 UTC

怎么上手

README 里没有找到可直接复制的安装命令

README 里没有找到可直接复制的安装命令,请到 README 或官方文档查看安装方式。

硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

5 个版本v5.5.0
  1. v5.5.05.5.0最新正式版2025-06-26 · 2025-06-26 14:45 UTC

    Removed deprecated methods and APIs

    • Calendar Events API.
    • Deals Pipelines API.
    • Associations methods from Companies, Deals and Engagements.
    • getAuthUrl method from OAuth2 API.
    • create and update methods from Owners API.
    • createWithToken and createWithOAuth2Token method from Factory.
    • Webhooks util.
  2. v5.4.05.4.02025-04-28 · 2025-04-28 06:10 UTC
    查看更新说明

    Changes:

    • Fixed implicitly nullable parameter declarations.
  3. v5.3.05.3.02024-10-07 · 2024-10-07 15:05 UTC

    这个版本没有写更新说明。

  4. v5.2.0 5.2.02024-02-06 · 2024-02-06 10:00 UTC
    查看更新说明

    Added type hinting for a few method of SevenShores\Hubspot\Http\Response.

  5. v5.1.15.1.12023-06-07 · 2023-06-07 12:44 UTC
    查看更新说明

    Fix Utils\OAuth2::getAuthUrl() (don't add empty scopes or optional scopes to OAuth url)

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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
    • 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) :new:
    • CRM Pipelines API (CrmPipelines)
    • Deals API
    • 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 :new:
    • Marketing Email API
    • Owners API :updated:
    • Products API :new:
    • Social Media API
    • Tickets API
    • Timeline API :updated:
    • Tracking Code API
    • Transactional Email API
    • Workflows API :updated:
    • Webhooks API