PHP code example of kristenlk / marketo-client

1. Go to this page and download the library: Download kristenlk/marketo-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kristenlk / marketo-client example snippets



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
    }
}


$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

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

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


$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

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

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


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


$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

$options = [
    "input" => [
        [
            "email" => "[email protected]",
            "firstName" => "Example1First",
            "lastName" => "Example1Last"
        ],
        [
            "email" => "[email protected]",
            "firstName" => "Example2First",
            "lastName" => "Example2Last"
        ]
    ]//, additional options
];

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


$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

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

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


$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 = { ... }


$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

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


$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

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


$demoMarketoClient = new DemoMarketoClient()->getMarketoClient();

$programChannel = "Live Event";

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