bickart/marketo-php

Marketo PHP REST API client

dev-master 2016-09-26 20:52 UTC

This package is not auto-updated.

Last update: 2024-05-11 17:34:30 UTC


README

Version Total Downloads License CodeClimate Test Coverage Build Status

Marketo 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.

ANNOUNCEMENT!

Setup

Composer:

composer require "bickart/marketo-php:1.0.*@dev"

Quickstart

Examples Using Factory

All following examples assume this step.

$hubspot = Amaiza\Marketo\Factory::create('api-key');

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

$hubspot = new Amaiza\Marketo\Factory([
  'key'      => 'demo',
  'oauth'    => false, // default
  'base_url' => 'https://api.hubapi.com' // default
]);

Note: The Client class checks for a HUBSPOT_SECRET environment variable if you don't include an api key or oauth token during instantiation.

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 Amaiza\Marketo\Http\Client;
use Amaiza\Marketo\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.

  • Companies 🆕
  • Leads 🆕
  • Opportunities 🆕
  • OpportunityRoles 🆕
  • SalesPersons 🆕
  • Stats