cloudcogsio/mautic-php-sdk

PHP library that simplifies interaction with the Mautic REST API. Built on top of the official Mautic PHP API library

dev-master 2025-03-20 20:56 UTC

This package is auto-updated.

Last update: 2025-03-20 20:56:28 UTC


README

Latest Stable Version PHP Version License

Cloudcogs Mautic PHP SDK is a lightweight PHP library that simplifies interaction with the Mautic REST API. Built on top of the official Mautic PHP API library, it provides a more convenient and intuitive interface for managing contacts, campaigns, emails, and more.

*** UNDER DEVELOPMENT ***

📦 Installation

Install via Composer:

composer require cloudcogsio/mautic-php-sdk

🚀 Basic Usage

Once installed, you can quickly start interacting with the Mautic API using the Cloudcogs Mautic PHP SDK.

1. Setup Configuration

Before initializing the SDK, create a config.php. See config.dist.php for a template. The SDK uses BasicAuth by default. OAuth2 support not available, but you can provide your own $auth object for usage.

<?php

use Cloudcogs\MauticPHP\Constants;

return [
    Constants::CONFIG_KEY_MAUTIC => [
        Constants::CONFIG_MAUTIC_USERNAME => '',
        Constants::CONFIG_MAUTIC_PASSWORD => '',
    ],
    Constants::CONFIG_MAUTIC_API_URL => 'https://xxxxxxxxxxx/api/',
];

2. Initialize the SDK

require_once './vendor/autoload.php';

use Cloudcogs\MauticPHP\Config;
use Cloudcogs\MauticPHP\SDK;

// Load configuration
$config = new Config(require_once './config/config.php');

// Initialize SDK
$mautic = new SDK($config);

3. Fetch and Display a Contact

// No $auth provided, BasicAuth will be used.
$contactsAPI = $mautic->getContactsApi();

The context classes can optionally accept an $auth object which allows you to use your own authentication method such as OAuth.

// Initiate the auth object
$initAuth = new ApiAuth();
$auth     = $initAuth->newAuth($settings);
$contactsAPI = $mautic->getContactsApi($auth);
$contact = $contactsAPI->getContactById(1);

echo "First Name: " . $contact->getFields()->getCore()->getFirstName();

See /example for more usage examples