eventfarm/marketo-client

Marketo REST API 的 PHP 客户端。

1.1 2016-11-03 21:02 UTC

This package is not auto-updated.

Last update: 2024-09-25 09:32:53 UTC


README

Travis Downloads Packagist Code Climate Test Coverage

此软件包提供与 Marketo REST API 交互的接口。

安装

$ composer require eventfarm/marketo-client

或者将以下行添加到您的 composer.json 文件中

{
    "require": {
        "eventfarm/marketo-client": "dev-master"
    }
}
$ composer install

项目默认设置

为了尽可能轻松地让您开始使用,我们提供默认的 REST 客户端和 Marketo 提供程序的实现,以便与该软件包一起使用。

Guzzle REST 客户端

我们的 REST 客户端实现了 PSR-7 HTTP 消息接口。

您可以使用提供的 GuzzleRestClient,或者使用您自己的,该客户端实现了我们的 RestClientInterface

KristenlkMarketoProvider

我们的默认 Marketo 提供程序是我的 Marketo Provider 库。

您可以使用提供的 KristenlkMarketoProvider,或者使用您自己的,该客户端实现了我们的 MarketoProviderInterface

示例客户端实现

<?php
namespace App;

use EventFarm\Marketo\Oauth\AccessToken;
use EventFarm\Marketo\MarketoClient;
use EventFarm\Marketo\TokenRefreshInterface;

class DemoMarketoClient implements TokenRefreshInterface
{
    public function getMarketoClient():MarketoClient
    {
        if (empty($this->marketo)) {
            $this->marketo = MarketoClient::withDefaults(
                'ACCESS_TOKEN',
                'TOKEN_EXPIRES_IN', // when the current access token expires (in seconds)
                'TOKEN_LAST_REFRESH', // when the current access token was last refreshed (as a UNIX timestamp)
                'CLIENT_ID',
                'CLIENT_SECRET',
                'BASE_URL',
                $this // TokenRefreshInterface
            );
        }
        return $this->marketo;
    }

    public function tokenRefreshCallback(AccessToken $token)
    {
        // CALLBACK FUNCTION TO STORE THE REFRESHED $token TO PERSISTENCE LAYER
    }
}

用法

活动

获取活动

文档 返回活动记录列表。有关完整选项列表,请参阅文档。

public function getCampaigns(array $options = array())

<?php
$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

$options = [
  "programName" => "My Marketo Program",
  "batchSize" => 10
];

$campaigns = $demoMarketoClient->campaigns()->getCampaigns($options);
// getCampaigns() can also be called without options.
// $campaigns = { ... }

触发活动

文档 将一组潜在客户传递给触发活动,以通过活动的流程运行。有关完整选项列表,请参阅文档。

  • 必须传递 campaignId 和包含一个 input 键(映射到包含潜在客户数据的数组)的选项数组给 triggerCampaign()

public function triggerCampaign(int $campaignId, array $options)

<?php
$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

$campaignId = 1029;
$options = [
    "input" => [
        "leads" => [
            [
                "id" => 1234
            ]
        ]
    ]//, additional options
];

$campaign = $demoMarketoClient->campaigns()->triggerCampaign($campaignId, $options);
// $campaign = { ... }

潜在客户字段

获取潜在客户字段

文档 返回目标实例中潜在客户对象的元数据,包括通过 API 可用交互的所有字段列表。

public function getLeadFields(array $options = array())

<?php
$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();
$leadFields = $demoMarketoClient->leadFields()->getLeadFields();
// $leadFields = { ... }

潜在客户

创建或更新潜在客户

文档 将潜在客户列表同步到目标实例。有关完整选项列表,请参阅文档。

  • 必须传递一个包含一个 input 键(映射到包含潜在客户数据的数组的数组)的选项数组到 createOrUpdateLeads()

public function createOrUpdateLeads(array $options)

默认情况下,Marketo 将同步操作类型(action)设置为 createOrUpdate,并将 lookupField 设置为 email。如果使用这些默认值

  • 电子邮件不是必需的;如果潜在客户数组中没有包含电子邮件,Marketo 将创建一个不带电子邮件的潜在客户。
  • 当包含电子邮件时,Marketo 将搜索具有该电子邮件的现有潜在客户。如果找到,Marketo 将使用发送的数据更新找到的潜在客户;如果没有找到,Marketo 将使用发送的数据创建一个新的潜在客户。
<?php
$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

$options = [
    "input" => [
        [
            "email" => "email1@example.com",
            "firstName" => "Example1First",
            "lastName" => "Example1Last"
        ],
        [
            "email" => "email2@example.com",
            "firstName" => "Example2First",
            "lastName" => "Example2Last"
        ]
    ]//, additional options
];

$leads = $demoMarketoClient->leads()->createOrUpdateLeads($options);
// $leads = { ... }

更新潜在客户的程序状态

文档 改变目标程序中一组潜在客户的程序状态。有关选项的完整列表,请参阅文档。

  • 必须传递一个 programId 和一个包含一个 input 键(映射到包含潜在客户数据的数组的数组)和一个 status 键(映射到程序状态)的选项数组到 updateLeadsProgramStatus()

public function updateLeadsProgramStatus(int $programId, array $options)

<?php
$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

$programId = 1234;
$options = [
    "input" => [
        [
            "id" => 1111
        ]
    ],
    "status" => "Registered"
];

$leads = $demoMarketoClient->leads()->updateLeadsProgramStatus($programId, $options);
// $leads = { ... }

按程序获取潜在客户

文档 获取指定程序成员的潜在客户列表。有关选项的完整列表,请参阅文档。

  • 必须传递一个 programIdgetLeadsByProgram()

public function getLeadsByProgram(int $programId, array $options = array())

<?php
$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

$programId = 1234;
$options = [
    "fields" => 'firstName,lastName,email,middleName,mktoIsPartner';
];

$leads = $demoMarketoClient->leads()->getLeadsByProgram($programId, $options);
// getLeadsByProgram() can also be called without options.
// $leads = { ... }

潜在客户分区

获取潜在客户分区

文档 返回目标实例中可用的分区的列表。有关选项的完整列表,请参阅文档。

public function getPartitions(array $options = array())

<?php
$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

$partitions = $demoMarketoClient->partitions()->getPartitions();
// $partitions = { ... }

程序

获取程序

文档 从目标实例检索可访问程序的列表。有关选项的完整列表,请参阅文档。

public function getPrograms(array $options = array())

<?php
$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

$programs = $demoMarketoClient->programs()->getPrograms();
// $programs = { ... }

状态

获取状态

文档 根据提供的名称检索渠道。有关选项的完整列表,请参阅文档。

  • 必须传递一个 programChannelgetStatuses()

public function getStatuses(string $programChannel, array $options = array())

<?php
$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

$programChannel = "Live Event";

$programs = $demoMarketoClient->statuses()->getStatuses($programChannel);
// $programs = { ... }