PHP code example of mtcextendee / mautic-badge-generator-bundle

1. Go to this page and download the library: Download mtcextendee/mautic-badge-generator-bundle 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/ */

    

mtcextendee / mautic-badge-generator-bundle example snippets


$api = new \Mautic\Api\Api($auth, $apiUrl);
$contactId = 1;
$badgeId = 2;
$response = $api->makeRequest(sprintf("badge/generator/%d/%d", $contactId, $badgeId));

// Bootup the Composer autoloader
l = 'http://mautic.site';
$settings = [
    'userName' => 'admin',
    'password' => 'mautic',
];
$initAuth = new ApiAuth();
$auth     = $initAuth->newAuth($settings, 'BasicAuth');
$api = new \Mautic\Api\Api($auth, $apiUrl);
$contactId = 1;
$badgeId = 2;
$response = $api->makeRequest(sprintf("badge/generator/%d/%d", $contactId, $badgeId));
if (isset($response['pdf'])) {
$result = base64_decode($response['pdf']);
// Write on file
file_put_contents('test.pdf', $result);
echo 'PDF created';
} elseif (isset($response['errors'][0]['message'])) {
echo $response['errors'][0]['message'];
}