1. Go to this page and download the library: Download combindma/laravel-mautic 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/ */
combindma / laravel-mautic example snippets
return [
/*
|--------------------------------------------------------------------------
| Auth Type
|--------------------------------------------------------------------------
| Version of the auth can be OAuth2 or BasicAuth. OAuth2 is the default value.
|
*/
'version' => env('MAUTIC_VERSION', 'OAuth2'), //or BasicAuth
/*
* Base URL of the Mautic instance
*/
'baseUrl' => env('MAUTIC_BASE_URL'),
/*
* Client/Consumer key from Mautic
*/
'clientKey' => env('MAUTIC_PUBLIC_KEY'),
/*
* Client/Consumer secret key from Mautic
*/
'clientSecret' => env('MAUTIC_SECRET_KEY'),
/*
* Redirect URI/Callback URI for this script
*/
'callback' => env('MAUTIC_CALLBACK'),
/*
|--------------------------------------------------------------------------
| Mautic App Credentials
|--------------------------------------------------------------------------
|
| This is used in case of BasicAuth
|
*/
'username' => env('MAUTIC_USERNAME'),
'password' => env('MAUTIC_PASSWORD'),
/*
* Enable or disable Mautic. Useful for local development when running tests.
*/
'apiEnabled' => env('MAUTIC_ENABLED', false),
/*
* Filename to use when storing mautic access token. Must be a json File
*/
'fileName' => 'mautic.json',
];
use Combindma\Mautic\Facades\Mautic;
//Create a new contact
Mautic::contacts()->create('[email protected]');
//with $parameters
$params = array(
'firstname' => 'bullet',
'lastname' => 'proof',
);
Mautic::contacts()->create('[email protected]', $params);
//Edit a given contact
Mautic::contacts()->edit($contactId, $params);
//Delete a contact
Mautic::contacts()->delete(567);//567 is the contact ID, change it to your needs
use Combindma\Mautic\Facades\Mautic;
//Add contact to a segment
Mautic::segments()->addContact($segmentId, $contactId);
//Create a contact and add it to a segment
$response = Mautic::contacts()->create(strtolower($request->input('email')));
if ($response && !$response->failed())
{
$contactId = $response->object()->contact->id;
Mautic::segments()->addContact(4, $contactId);//4 is the segment ID, change it to your needs
}
//Remove a contact from a given segment
Mautic::segments()->removeContact($segmentId, $contactId);
use Combindma\Mautic\Facades\Mautic;
//Add UTM tags to a given contact
$data = array(
'utm_campaign' => 'apicampaign',
'utm_source' => 'fb',
'utm_medium' => 'social',
'utm_content' => 'fbad',
'utm_term' => 'mautic api',
'useragent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0',
'url' => '/product/fbad01/',
'referer' => 'https://google.com/q=mautic+api',
'query' => ['cid'=>'abc','cond'=>'new'], // or as string with "cid=abc&cond=new"
'remotehost' => 'example.com',
'lastActive' => '2017-01-17T00:30:08+00:00'
);
Mautic::utmTags()->addUtmTag($contactId, $data);
//Remove a given UTM Tag from contact
Mautic::utmTags()->removeUtmTag($utmId, $contactId);
use Combindma\Mautic\Facades\Mautic;
//Add contact points
$data = array(
'eventName' => 'Score via api',
'actionName' => 'Adding',
);
Mautic::points()->addPoints($contactId, 10, $data);//$data is optional
//Subtract contact points
$data = array(
'eventname' => 'Score via api',
'actionname' => 'Subtracting',
);
Mautic::points()->subtractPoints($contactId, 10, $data);//$data is optional
use Combindma\Mautic\Facades\Mautic;
//ing $email) {
$response = Mautic::contacts()->create(strtolower($request->input('email')));
if ($response && !$response->failed())
{
$contactId = $response->object()->contact->id;
Mautic::segments()->addContact(4, $contactId);//4 is the segment ID, change it to your needs
}
});
//In your controller, you only need to call your method
Mautic::sbscribe('[email protected]');