PHP code example of vpmv / marketo-client

1. Go to this page and download the library: Download vpmv/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/ */

    

vpmv / marketo-client example snippets



namespace App;

use VPMV\Marketo\Oauth\AccessToken;
use VPMV\Marketo\MarketoClient;

class DemoMarketoAPI extends Marketo
{
    public function __cosntruct() {
        parent::__construct($this->getMarketoClient());
    }

    public function getMarketoClient():MarketoClient
    {
        if (empty($this->client)) {
            $this->client = MarketoClient::with(
                'CLIENT_ID',
                'CLIENT_SECRET',
                'BASE_URL',
                $this->getRefreshTokenFromCache(),               
                $this->tokenRefreshCallback
            );
        }
        return $this->client;
    }
    
    private function getRefreshTokenFromCache(): ?AccessToken {
        // get token from cache
        return new AccessToken('my_token', 300, 1642768705);
        // or return null
    }

    public function tokenRefreshCallback(AccessToken $token)
    {
        // store the token
    }
}


$demoMarketo = new DemoMarketoAPI();

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

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


$demoMarketo = new DemoMarketoAPI();

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

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


$demoMarketo = new DemoMarketoAPI();
$leadFields = $demoMarketo->leadFields()->getLeadFields();
// $leadFields = { ... }


$demoMarketo = new DemoMarketoAPI();

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

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


$demoMarketo = new DemoMarketoAPI();

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

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


$demoMarketo = new DemoMarketoAPI();

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

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


$demoMarketo = new DemoMarketoAPI();

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


$demoMarketo = new DemoMarketoAPI();

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


$demoMarketo = new DemoMarketoAPI();

$programChannel = "Live Event";

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