Skip to content

QuantiCZ/MailQ-PHP-Library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MailQ PHP library

Instalation

Composer

composer require quanti/mailq-connector

Using in Nette

Add this section to your config. You should use different URL and API key for development and production environment.

Usage

There is MailQ object which is facade to whole MailQ REST API. Most common use case is only one company in MailQ per customer. You need to instantiate MailQ object with company ID. Because there are also customers with multiple companies there is MailQFactory which creates MailQ for specific company.

$apiKey = "6e2211bf472a9478f03420fb5897e324c57d05fc27bc0e871083275e98eec344";
$apiUrl = "http://mailq-test.quanti.cz/api/v2";
$mailqFactory = new MailQFactory($apiUrl);
$companyId = 1;
$mailq = $mailqFactory->createMailQ($companyId, $apiKey);

Running sandbox with Docker

Sandbox is minimum application for playing around with PHP MailQ library.

Windows

  • Run docker run --rm -it -v %cd%:/app composer install to install PHP dependencies
  • Run docker run --rm -it -v %cd%:/app php:cli php /app/sandbox/sandbox.php <API key> <company ID>

Unix

  • Run docker run --rm -it -v $(pwd):/app composer install to install PHP dependencies
  • Run docker run --rm -it -v $(pwd):/app php:cli php /app/sandbox/sandbox.php <API key> <company ID>

Where API key is your private company key used for authentication and company ID is integer number used for identication company.

Get all campaigns

$campaigns = $mailq->getCampaigns();

Get single campaign

$campaignId = 1;
$campaigns = $mailq->getCampaign();

Get company

$company = $mailq->getCompany();

Regenerate API key

Use this with caution! After regenerating API key application will throw errors because you have already create connection

$apiKey = $mailq->regenerateApiKey();

Get all log messages

$logMessagesEntity = $mailq->getLogMessages();

Get single log message

$logMessageId = 1;
$logMessageEntity = $mailq->getLogMessage($logMessageId);

Create newsletter

$data = [
    "name" => "Awesome newsletter",
    "campaign"=> "Spring 2016",
    "subject" => "Buy our new product",
    "senderEmail" => "[email protected]",
    "sendAs" => "Awesome Company",
    "from" => "2018-07-01T00:00:00+00:00",
    "to" => "2018-07-02T00:00:00+00:00",
    "text"=> "TmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciw=",
    "automaticTime"=> false,
    "recipientsListId"=>1,
    "templateUrl" => "http://example.org/newsletter.html",
    "unsubscribeTemplateUrl" => "http://example.org/unsubscribe.html"
];
$newsletter = new \MailQ\Entities\v2\NewsletterEntity($data);
$mailq->createNewsletter($newsletter);
$newsletterId = $newsletter->getId();

Update newsletter

$data = [
    "id" => 1,
    "name" => "Awesome newsletter",
    "campaign" => "Spring 2016",
    "subject" => "Buy our new product",
    "senderEmail" => "[email protected]",
    "sendAs" => "Awesome Company",
    "from" => "2018-07-01T00:00:00+00:00",
    "to" => "2018-07-02T00:00:00+00:00",
    "text" => "TmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciw=",
    "automaticTime" => false,
    "recipientsListId" => 1,
    "templateUrl" => "http://example.org/newsletter.html",
    "ampTemplateUrl" => "http://example.org/ampNewsletter.html",
    "unsubscribeTemplateUrl" => "http://example.org/unsubscribe.html"
];
$newsletter = new \MailQ\Entities\v2\NewsletterEntity($data);
$mailq->updateNewsletter($newsletter);
$newsletterId = $newsletter->getId();

Update newsletter in ready state

$data = [
    "id" => 1,
    "name" => "Awesome newsletter",
    "campaign" => "Spring 2016",
    "subject" => "Buy our new product",
    "senderEmail" => "[email protected]",
    "replyToEmail" : "[email protected]",
    "sendAs" => "Awesome Company",
    "text" => "TmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciw=",
    "automaticTime" => false,
    "templateUrl" => "http://example.org/newsletter.html",
    "ampTemplateUrl" => "http://example.org/ampNewsletter.html",
    "unsubscribeTemplateUrl" => "http://example.org/unsubscribe.html"
];
$newsletter = new \MailQ\Entities\v2\NewsletterEntity($data);
$mailq->updateNewsletter($newsletter);
$newsletterId = $newsletter->getId();

Get all newsletters

$newsletters = $mailq->getNewsletters();

Get newsletter

$newsletterId = 1;
$newsletter = $mailq->getNewsletter($newsletterId);

Send test e-mail

$newsletterId = 1;
$email = "[email protected]";
$mailq->sendTestEmail($email,$newsletterId);

Start preparation of newsletter

$newsletterId = 1;
$mailq->startNewsletter($newsletterId);

Stop preparation of newsletter

$newsletterId = 1;
$mailq->stopNewsletter($newsletterId);

Create notification

$data = [
    "name" => "First Notification",
    "code" => "N1",
    "subject" => "{{orderNumber}} order is ready",
    "sendAs" => "Awesome Company",
    "text" => "QWx0ZXJuYXRpdmUgYmFzZTY0IGVtYWlsIHRleHQ=",
    "template" => "QWx0ZXJuYXRpdmUgYmFzZTY0IGVtYWlsIHRleHQ=",
    "ampTemplate" => "QWx0ZXJuYXRpdmUgYmFzZTY0IGVtYWlsIHRleHQ=",
    "appliedSenderEmail" => "[email protected]"
];
$notification = new \MailQ\Entities\v2\NotificationEntity($data);
$mailq->createNotification($notification);
$notificationId = $notification->getId();

Update notification

$data = [
    "id" => 1,
    "name" => "First Notification",
    "code" => "N1",
    "subject" => "{{orderNumber}} order is ready",
    "sendAs" => "Awesome Company",
    "text" => "QWx0ZXJuYXRpdmUgYmFzZTY0IGVtYWlsIHRleHQ=",
    "template" => "QWx0ZXJuYXRpdmUgYmFzZTY0IGVtYWlsIHRleHQ=",
    "ampTemplate" => "QWx0ZXJuYXRpdmUgYmFzZTY0IGVtYWlsIHRleHQ=",
    "appliedSenderEmail" => "[email protected]"
];
$notification = new \MailQ\Entities\v2\NotificationEntity($data);
$mailq->updateNotification($notification);

Get all notifications

$notifications = $mailq->getNotifications();

Delete notification

$notificationId = 1;
$mailq->deleteNotification($notificationId);

Send notification e-mail

In data section are all values which will be used in notification. Keys of associative array are variable names and values are values.

$data = [
    "recipientEmail" => "[email protected]",
    "data" => [
        "key1" => "value1",
        "key2" => "value2"
    ],
    "attachments" => [
        [
            "displayName" =>  "Priloha 1",
            "link" => "http://example.org/test.txt",
            "source" => "dGVzdHM=",
            "mimeType" => "text/plain"
        ],
        [
            "displayName" => "Priloha 2",
            "link" => "http://example.org/image.png",
            "source" => "R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",
            "mimeType" => "image/png"
        ]
    ]
];
$notificationId = 1;
$notificationData = new \MailQ\Entities\v2\NotificationDataEntity($data);
$mailq->sendNotificationEmail($notificationData,$notificationId);
$notificationDataId = $notificationData->getId();

Get notification e-mail

$notificationId = 1;
$notificationDataId = 2;
$notificationData = $mailq->getNotificationData($notificationId,$notificationDataId);

Get all notification e-mails

$notificationId = 1;
$email = "[email protected]";
$notificationsData = $mailq->getNotificationsData($notificationId,$email);

Create recipients list

$mailq = $mailqFactory->createMailQ($companyId);
$data = [
    "name" => "All clients",
    "description" => "All clients of our awesome company",
    "variables" => ["salutation","gender"],
    "formVisible" => true
];
$recipientsList = new \MailQ\Entities\v2\RecipientsListEntity($data);
$mailq->createRecipientsList($recipientsList);
$recipientsListId = $recipientsList->getId();

Delete recipients list

$recipientsListId = 1;
$mailq->deleteRecipientsList($recipientListId);

Get recipients list

$recipientsListId = 1;
$recipientsList = $mailq->getRecipientsList($recipientListId);

Get recipients lists

You can specify e-mail and API returns only recipients list which contains this e-mail

$email = "[email protected]";
$recipientsLists = $mailq->getRecipientsLists($email);

Get all recipients

$recipientsListId = 1;
$recipients = $mailq->getRecipients($recipientsListId);

Add multiple recipients at once

$data = [
	"recipients" => [
		[
			"email" => "[email protected]",
	        "data" => [
	            "key1" => "value1",
	            "key2" => "value2"
	        ]
		]
	]
];
$recipients = new \MailQ\Entities\v2\RecipientsEntity($data);
$recipientsListId = 1;
$validate = false;
$mailq->addRecipients($recipients,$recipientsListId,$validate);

Update or create recipient

$data = [
	"email" => "[email protected]",
    "data" => [
        "key1" => "value1",
        "key2" => "value2"
    ]
];
$recipient = new \MailQ\Entities\v2\RecipientEntity($data);
$recipientsListId = 1;
$validate = false;
$mailq->updateRecipient($recipient,$recipientsListId,$validate);

Get all recipients list unsubscriber

$recipientsListId = 1;
$unsubscribers = $mailq->getRecipientListUnsubscribers($recipientsListId);

Add recipients list unsubscriber

$recipientsListId = 1;
$email = "[email protected]";
$mailq->addRecipientListUnsubscriber($emails,$recipientsListId);

Add recipients list unsubscribers

$data = [
	"emails" => [
		[
			"email" => "[email protected]"
		],
		[
			"email" => "[email protected]"
		]
	]
];
$recipientsListId = 1;
$emails = new \MailQ\Entities\v2\EmailAddressesEntity($data);
$mailq->addRecipientListUnsubscribers($emails,$recipientsListId);

Delete recipients list unsubscriber

$recipientsListId = 1;
$email = "[email protected]";
$mailq->deleteRecipientListUnsubscriber($emails,$recipientsListId);

Create single SMS notification

$data = [
	"name" => "SMS notification",
    "code" => "S1",
    "template" => "U01TIHRlc3Qge3t2YXJpYWJsZX19"
];
$smsNotification = new \MailQ\Entities\v2\SmsNotificationEntity($data);
$mailq->createSmsNotification($smsNotification);
$smsNotificationId = $smsNotification->getId();

Update single SMS notification

$data = [
	"name" => "SMS notification",
    "code" => "S1",
    "template" => "U01TIHRlc3Qge3t2YXJpYWJsZX19"
];
$smsNotification = new \MailQ\Entities\v2\SmsNotificationEntity($data);
$mailq->updateSmsNotification($smsNotification);

Delete SMS notification

$smsNotificationId = 1;
$mailq->deleteSmsNotification($smsNotification);

Get all SMS notifications

$notifications = $mailq->getSmsNotifications();

Get single SMS notification

$smsNotificationId = 1;
$notifications = $mailq->getSmsNotification($smsNotificationId);

Send SMS

$smsNotificationId = 1;
$data = [
	"toNumber" => "+420123456789",
    "data" => [
        "key1" => "value1",
        "key2" => "value2"
    ]
];
$sms = new \MailQ\Entities\v2\SmsEntity($data);
$mailq->sendSms($sms,$smsNotificationId);
$smsId = $sms->getId();

Send SMS batch

$smsNotificationId = 1;
$data = [
	"batch" => [
        [    
            "id" => 1,
            "toNumber" => "+420123456789",
            "data" => [         
                "text" => "value1"   
            ]
        ],
        [     
            "id" => 2,
            "toNumber" => "+420123456789",
            "data" => [        
                "text" => "value2"   
            ]
        ]

    ]
];
$smsBatch = new \MailQ\Entities\v2\SmsBatchEntity($data);
$smsBatchResultEntity = $mailq->sendSmsBatch($smsBatch,$smsNotificationId);

Get all sender emails

$senderEmails = $mailq->getSenderEmails();

Get single sender email

$senderEmailId = 1;
$senderEmail = $mailq->getSenderEmail($senderEmailId);

Get all users

$users = $mailq->getUsers();

Get single user

$userId = 1;
$user = $mailq->getUser($userId);