costamateus/laravel-mautic-api

Free and Open Source Marketing Automation API

v3.0.1 2023-09-25 14:13 UTC

This package is auto-updated.

Last update: 2024-03-25 15:30:01 UTC


README

Free and Open Source Marketing Automation API

Requirements

v 2.0.7

  • Laravel ^8.0
  • PHP ^7.3 or newer
  • cURL support

v 3.0.0+

  • Laravel ^9.0
  • PHP ^8.0.2 or newer
  • cURL support

Mautic Setup

The API must be enabled in Mautic.

Within Mautic, go to the Configuration page (located in the Settings menu) and under API Settings enable Mautic's API. You can also choose which OAuth2 protocol to use here.

After saving the configuration, go to the API Credentials page (located in the Settings menu) and create a new client. Enter the callback/redirect URI ( must be https://your-app.com/mautic/application/register) that the request will be sent from. Click Apply then copy the Client ID and Client Secret to the application that will be using the API.

Installation

First, you'll need to require the package with Composer:

composer require costamateus/laravel-mautic-api

Aftwards, run composer update from your command line.

Then, update config/app.php by adding an entry for the service provider.

'providers' => [
	// ...
	Triibo\Mautic\MauticServiceProvider::class,
],

Then, register class alias by adding an entry in aliases section

'aliases' => [
    // ...
    'Mautic' => Triibo\Mautic\Facades\Mautic::class,
],

Finally, from the command line run php artisan vendor:publish --provider="Triibo\Mautic\MauticServiceProvider" to publish the default configuration file. This will publish a configuration file name mautic.php, consumer migration and consumer model.

Then, run php artisan migrate migration command to create consumer table in your database.

Configuration

You need to add your client id, client secret and callback url for OAuth2 or username and password for BasicAuth in config/mautic.php. Or put it in your .env file.

## OAuth2
MAUTIC_BASE_URL="https://your-mautic.com"
MAUTIC_PUBLIC_KEY="publicKey"
MAUTIC_SECRET_KEY="secretKey"
MAUTIC_CALLBACK="https://your-app.com/mautic/application/register"
## or BasicAuth
MAUTIC_BASE_URL="https://your-mautic.com"
MAUTIC_USERNAME="username"
MAUTIC_PASSWORD="password"

Authorization

This Library only supports OAuth2 and BasicAuth Authentication. For OAuth2 you need to create a OAuth2 client in order to use the api.

Registering Application

In order to register you application with mautic ping this url this is one time registration.

http://your-app.com/mautic/application/register

Usage

Add Mautic Facade in your controller.

use Triibo\Mautic\Facades\Mautic;

Send a request to mautic ( Example )

Create a new contact in mautic.

$params = array(
    'firstname' => 'Prince',
    'lastname'  => 'Ali Khan',
    'email'     => 'princealikhan08@gmail.com'
);

Mautic::request('POST','contacts/new',$params);

Get List of all contacts

Mautic::request('GET','contacts');

Get a unique contact

Mautic::request('GET','contacts/1');
//where 1 is unique id for a contact.

Delete a contact

Mautic::request('Delete','contacts/1/delete');
And many more endpoints support by mautic.

List of Endpoints supported by Mautic.

Assets

[
    "assets",
    "assets/new",
    "assets/{asset_id}",
    "assets/{asset_id}/edit",
    "assets/{asset_id}/delete"
]

Campaigns

[
    "campaigns",
    "campaigns/new",
    "campaigns/{campaign_id}",
    "campaigns/{campaign_id}/contacts",
    "campaigns/clone/{campaign_id}",
    "campaigns/{campaign_id}/edit",
    "campaigns/{campaign_id}/delete",
    "campaigns/{campaign_id}/contact/{contact_id}/add",
    "campaigns/{campaign_id}/contact/{contact_id}/remove"
]

Categories

[
    "categories",
    "categories/new",
    "categories/{category_id}",
    "categories/{category_id}/edit",
    "categories/{category_id}/delete"
]

Companies

[
    "companies",
    "companies/new",
    "companies/{company_id}",
    "companies/{company_id}/edit",
    "companies/{company_id}/delete",
    "companies/{company_id}/contact/{contact_id}/add",
    "companies/{company_id}/contact/{contact_id}/remove"
]

Contacts

[
    "contacts",
    "contacts/batch/new",
    "contacts/batch/edit",
    "contacts/batch/delete",
    "contacts/new",
    "contacts/{contact_id}",
    "contacts/{contact_id}/edit",
    "contacts/{contact_id}/delete",
    "contacts/{contact_id}/dnc/{channel}/add",
    "contacts/{contact_id}/dnc/{channel}/remove",
    "contacts/{contact_id}/utm/add",
    "contacts/{contact_id}/utm/{utm_id}/remove",
    "contacts/{contact_id}/points/plus/{points}",
    "contacts/{contact_id}/points/minus/{points}",
    "contacts/list/owners",
    "contacts/list/fields",
    "contacts/{contact_id}/notes",
    "contacts/{contact_id}/segments",
    "contacts/{contact_id}/campaigns"
    "contacts/{contact_id}/events",
    "contacts/{contact_id}/activity",
    "contacts/activity",
    "contacts/{contact_id}/companies",
    "contacts/{contact_id}/devices"
]

Data

[
    "data",
    "data/{type}",
    "data/emails.in.time",
    "data/sent.email.to.contacts",
    "data/most.hit.email.redirects"
]

Dynamic Content

[
    "dynamiccontents",
    "dynamiccontents/new",
    "dynamiccontents/{dynamiccontent_id}",
    "dynamiccontents/{dynamiccontent_id}/edit",
    "dynamiccontents/{dynamiccontent_id}/delete"
]

Emails

[
    "emails",
    "emails/new",
    "emails/{email_id}",
    "emails/{email_id}/edit",
    "emails/{email_id}/delete",
    "emails/{email_id}/send",
    "emails/reply/{tracking_hash}"
]

Fields

[
    "fields/company",
    "fields/company/new",
    "fields/company/{company_id}",
    "fields/company/{company_id}/edit",
    "fields/company/{company_id}/delete",
    "fields/contact",
    "fields/contact/new",
    "fields/contact/{contact_id}",
    "fields/contact/{contact_id}/edit",
    "fields/contact/{contact_id}/delete"
]

Files

[
    "files/images",
    "files/{dir}/new",
    "files/{dir}/{file}/delete"
]

Forms

[
    "forms",
    "forms/new",
    "forms/{form_id}",
    "forms/{form_id}/edit",
    "forms/{form_id}/delete",
    "forms/{form_id}/fields/delete",
    "forms/{form_id}/actions/delete",
    "forms/{form_id}/submissions",
    "forms/{form_id}/submissions/contact/{contact_id}",
    "forms/{form_id}/submissions/{submission_id}"
]

Marketing Messages

[
    "messages",
    "messages/new",
    "messages/{message_id}",
    "messages/{message_id}/edit",
    "messages/{message_id}/delete"
]

Notes

[
    "notes",
    "notes/new",
    "notes/{note_id}",
    "notes/{note_id}/edit",
    "notes/{note_id}/delete"
]

Notifications

[
    "notifications",
    "notifications/new",
    "notifications/{notification_id}",
    "notifications/{notification_id}/edit",
    "notifications/{notification_id}/delete"
]

Pages

[
    "pages",
    "pages/new",
    "pages/{page_id}",
    "pages/{page_id}/edit",
    "pages/{page_id}/delete"
]

Points Actions

[
    "points",
    "points/new",
    "points/{point_id}",
    "points/{point_id}/edit",
    "points/{point_id}/delete",
    "points/actions/types",
    "points/triggers",
    "points/triggers/new",
    "points/triggers/{point_id}",
    "points/triggers/{point_id}/edit",
    "points/triggers/{point_id}/delete",
    "points/triggers/{point_id}/events/delete",
    "points/triggers/events/types"
]

Reports

[
    "reports",
    "reports/{report_id}"
]

Roles

[
    "roles",
    "roles/new",
    "roles/{role_id}",
    "roles/{role_id}/edit",
    "roles/{role_id}/delete"
]

Segments

[
    "segments",
    "segments/new",
    "segments/{segment_id}",
    "segments/{segment_id}/edit",
    "segments/{segment_id}/delete",
    "segments/{segment_id}/contact/{contact_id}/add",
    "segments/{segment_id}/contact/{contact_id}/remove"
]

Text messages

[
    "smses",
    "smses/new",
    "smses/{sms_id}",
    "smses/{sms_id}/edit",
    "smses/{sms_id}/delete",
    "smses/{sms_id}/contact/{contact_id}/send"
]

Stages

[
    "stages",
    "stages/new",
    "stages/{stage_id}",
    "stages/{stage_id}/edit",
    "stages/{stage_id}/delete",
    "stages/{stage_id}/contact/{contact_id}/add",
    "stages/{stage_id}/contact/{contact_id}/remove"
]

Stats

[
    "stats",
    "stats/{table}"
]

Tags

[
    "tags",
    "tags/new",
    "tags/{tag_id}",
    "tags/{tag_id}/edit",
    "tags/{tag_id}/delete"
]

Themes

[
    "themes",
    "themes/new",
    "themes/{theme_name}",
    "themes/{theme_name}/delete"
]

Tweets

[
    "tweets",
    "tweets/new",
    "tweets/{tweet_id}",
    "tweets/{tweet_id}/edit",
    "tweets/{tweet_id}/delete"
]

Users

[
    "users",
    "users/new",
    "users/{user_id}",
    "users/{user_id}/edit",
    "users/{user_id}/delete",
    "users/self",
    "users/{user_id}/permissioncheck"
]

Webhooks

[
    "hooks",
    "hooks/new",
    "hooks/{hook_id}",
    "hooks/{hook_id}/edit",
    "hooks/{hook_id}/delete",
    "hooks/triggers"
]

Please refer to Documentation. for all customizable parameters.