Skip to content

eduardoguerrero/hubspot-api-client-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hubspot API client PHP

What is HubSpot?

HubSpot’s CRM platform has all the tools and integrations you need for marketing, sales, content management, and customer service. Each product in the platform is powerful alone, but the real magic happens when you use them together.

Installing

composer require hubspot/api-client

Contacts

Get all contacts

use HubSpot\Http\Client;
use HubSpot\Resources\Contact;

$client = new Client(['baseUrl' => 'https://api.hubapi.com', 'apikey' => 'XXXX-XXXX']);
$contact = new Contact($client);
// Control what is returned via the properties query param.
$queryParams = [
     'limit' => 2,         // The maximum number of results to display per page.
     'archived' => false,  // Whether to return only results that have been archived.
];
$response = $contact->getAll($queryParams);
$data = $response->getData();

Get contact by id

use HubSpot\Http\Client;
use HubSpot\Resources\Contact;

$client = new Client(['baseUrl' => 'https://api.hubapi.com', 'apikey' => 'XXXX-XXXX']);
$contact = new Contact($client);
$queryParams = [
     'archived' => false, // Whether to return only results that have been archived.
];
$customerId = 142290864;
$response = $contact->getById($customerId, $queryParams);
$data = $response->getData();

Get contact by property

use HubSpot\Http\Client;
use HubSpot\Resources\Contact;

$client = new Client(['baseUrl' => 'https://api.hubapi.com', 'apikey' => 'XXXX-XXXX']);
$contact = new Contact($client);
$options = [
   'body' => [
       'filterGroups' => [
           [
              'filters' => [
                 [
                   'value' => 'escobarguerrero@gmail.com',
                   'propertyName' => 'email',
                   'operator' => 'EQ'
                 ]
              ]
           ]
       ]
  ]
];
$response = $contact->getByProperty($options);
$data = $response->getData();

Create contact

use HubSpot\Http\Client;
use HubSpot\Resources\Contact;

$client = new Client(['baseUrl' => 'https://api.hubapi.com', 'apikey' => 'XXXX-XXXX']);
$contact = new Contact($client);
$properties = [
      'body' => [
         'properties' => [
             'company' => 'Home',
             'email' => 'escobarguerrerp@gmail.com',
             'firstname' => 'René,
             'lastname' => 'Escobar',
             'phone' => '(503) 0000-0000',
             'website' => 'home.net'
         ]
     ]
];
$response = $contact->create($properties);

Deals

Get all deals

use HubSpot\Http\Client;
use HubSpot\Resources\Deal;

$client = new Client(['baseUrl' => 'https://api.hubapi.com', 'apikey' => 'XXXX-XXXX']);
$deal = new Deal($client);
// Control what is returned via the properties query param.
$queryParams = [
     'limit' => 2,         // The maximum number of results to display per page.
     'archived' => false,  // Whether to return only results that have been archived.
];
$response = $deal->getAll($queryParams);
$data = $response->getData()

Get deal by id

use HubSpot\Http\Client;
use HubSpot\Resources\Deal;

$client = new Client(['baseUrl' => 'https://api.hubapi.com', 'apikey' => 'XXXX-XXXX']);
$deal = new Deal($client);
$queryParams = [
     'archived' => false, // Whether to return only results that have been archived.
];
$dealId = 1919254657;
$response = $deal->getById($dealId, $queryParams);
$data = $response->getData()

Create deal

use HubSpot\Http\Client;
use HubSpot\Resources\Deal;

$client = new Client(['baseUrl' => 'https://api.hubapi.com', 'apikey' => 'XXXX-XXXX']);
$deal = new Deal($client);
$properties = [
      'body' => [
         'properties' => [
             'amount'=> '599.00',
             'closedate'=> '2019-12-07T16:50:06.678Z',
             'dealname'=> 'Custom data integrations',
             'hubspot_owner_id'=> '45097310',
             'pipeline'=> 'Pipeline test'
         ]
      ]
];
$response = $deal->create($properties);
$data = $response->getData()

Update deal

use HubSpot\Http\Client;
use HubSpot\Resources\Deal;

$client = new Client(['baseUrl' => 'https://api.hubapi.com', 'apikey' => 'XXXX-XXXX']);
$deal = new Deal($client);
// Properties to update
$properties = [
      'body' => [
             'properties' => [
             'amount' => '699.00',
             'closedate' => '2021-04-01T16:50:06.678Z',
             'dealname' => 'Test custom data integrations',
             'hubspot_owner_id' => '45097310',
             'pipeline' => 'Pipeline test'
         ]
      ]
];
$dealId = 5026209383;
$response = $deal->updateById($dealId, $properties);
$data = $response->getData()

Associate a deal with another object

use HubSpot\Http\Client;
use HubSpot\Resources\Deal;

const ASSOCIATION_DEAL_TO_CONTACT = 'contacts';
const ASSOCIATION_TYPE_DEAL_TO_CONTACT = 'deal_to_contact';
$client = new Client(['baseUrl' => 'https://api.hubapi.com', 'apikey' => 'XXXX-XXXX']);
$deal = new Deal($client);
$associate = new AssociateDeal();
$associate
    ->setDealId($dealId)
    ->setToObjectType(self::ASSOCIATION_DEAL_TO_CONTACT)
    ->setToObjectId($toObjectId)
    ->setAssociationType(self::ASSOCIATION_TYPE_DEAL_TO_CONTACT);
$data = $deal->associateWithObject($associate);

Change deal status

use HubSpot\Http\Client;
use HubSpot\Resources\Deal;

$client = new Client(['baseUrl' => 'https://api.hubapi.com', 'apikey' => 'XXXX-XXXX']);
$deal = new Deal($client);
$dealStatus = new DealStatus();
$dealStatus
    ->setLastModifiedDate(date("Y-m-d"))
    ->setDealStage('stage')
    ->setOrderStatus('order_status'),
    ->setFulfillmentStatus('new');
$dealId = 5026209383;
$properties = [
    'body' => [
        'properties' => [
            'dealstage' => $dealStatus->getDealStage(),
            'order_status' => $dealStatus->getOrderStatus(),
            'unific_fulfillment_status'=> $dealStatus->getFulfillmentStatus(),
            'hs_lastmodifieddate' => $dealStatus->getLastModifiedDate()
        ]
    ]
];
$data = $deal->updateById($dealId, $properties);

Runt tests

./vendor/phpunit/phpunit/phpunit tests/

Feel free to fork it or do whatever you want with it.

License: https://creativecommons.org/licenses/by/3.0/

About

hubspot api client php

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages