Code Monkey home page Code Monkey logo

hubspot-php's Introduction

HubSpot PHP API client

Version Total Downloads License

Hubspot API client. The sequel to my perfectly functional wrapper of HubSpot/haPihP. client. However, this is a complete re-write and includes some of the new COS/v2 endpoints.

Setup

Composer:

composer require "ryanwinchester/hubspot-php:~1.0"

Quickstart

Examples Using Factory

All following examples assume this step.

$hubspot = SevenShores\Hubspot\Factory::create('api-key');

// OR instantiate by passing a configuration array.
// The only required value is the 'key'

$hubspot = new SevenShores\Hubspot\Factory([
  'key'      => 'demo',
  'oauth'    => false, // default
  'base_url' => 'https://api.hubapi.com' // 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::createWithToken())

$hubspot = new SevenShores\Hubspot\Factory([
  'key'      => 'demo',
  'oauth'    => false, // default
  'base_url' => 'https://api.hubapi.com' // default
],
null,
[
  'http_errors' => true // 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 true, 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("[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) {
    //
}

Status

If you see something not planned, that you want, make an issue and there's a good chance I will add it.

  • Blogs (COS) ๐Ÿ†•
  • Blog Authors (COS) ๐Ÿ†•
  • Blog Posts (COS) ๐Ÿ†•
  • Blog Topics (COS) ๐Ÿ†•
  • Companies ๐Ÿ†•
  • Company Properties ๐Ÿ†•
  • Contacts
  • Contact Lists
  • Contact Properties
  • Deals ๐Ÿ†•
  • Email ๐Ÿ†•
  • Email Events ๐Ÿ†•
  • Engagements
  • Events (Enterprise) ๐Ÿ†•
  • Files (COS) ๐Ÿ†•
  • Forms
  • Keywords
  • Owners
  • Page Publishing (COS) ๐Ÿ†•
  • Social Media
  • Templates (COS) ๐Ÿ†•
  • Timeline ๐Ÿ†•
  • Workflows

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.