This project aims to provide a native and easy-to-use PHP API for Compost Marketing Carma platform. Compost Carma is an email marketing platform mainly used for newsletter generation and recipients lists management.
This API is built on the existing REST API provided by Compost (documentation available here).
This project is still in early development - please do not use this in your project just yet
Use the RESTAPIConfig along the RESTBasicAPIAuthentification for now to authenticate with a valid API Username/Password combination.
<?php
use CarmaAPI\config\RESTAPIConfig;
use CarmaAPI\config\RESTBasicAPIAuthentification;
use CarmaAPI\CarmaAPI;
$cfg = new CarmaAPI\config\RESTAPIConfig("<server no>", "<customer id>");
$cfg->setAuthentification(new RESTBasicAPIAuthentification("<api username>", "<api password>"));
$api = new CarmaAPI($cfg);The API uses a series of endpoint as a mechanism to facilitate the overall use of the API. An endpoint represents a valid REST resource in Carma's API where some operations are available (list, create, delete, update, etc; your basic CRUD methods are generally present). Methods in the endpoints may have two purposes (for now):
- output model instances representing the actual data;
- another endpoint instance used to create a logical navigation between endpoints.
ContactEndpoint- used for operations on a single contact in a recipient listContactsListEndpoint- used for operations on contacts listsRecipientListEndpoint- used for operations on a single recipient listRecipientsListsEndpoint- used for operations on recipients lists
<?php
// ... configure & login to api and stuff ...
$lists = $api->lists()->getAll();
// $lists = array(\CarmaAPI\models\ListDto)<?php
foreach($api->lists()->getById(1)->contacts()->iterator(CarmaAPIConstants::CONTACTS_LIST_ITERATOR_UNSUBSCRIBED) as $unsubscribed_contact) {
// $unsubscribed_contact = \CarmaAPI\models\ContactDto
echo "I am unsubscribed :(";
}
foreach($api->lists()->getById(1)->contacts()->iterator(CarmaAPIConstants::CONTACTS_LIST_ITERATOR_BOUNCED) as $bounced_contact) {
// $bounced_contact = \CarmaAPI\models\ContactDto
echo "I bounced :(";
}
foreach($api->lists()->getById(1)->contacts()->iterator() as $contact) {
// $contact = \CarmaAPI\models\ContactDto
echo $contact->firstName . " " . $contact->lastName;
}<?php
$msgs = $api->lists()->contacts()->getByOriginalId("<originalid>")->messages();
// $msgs = array(\CarmaAPI\models\MessagesDto)TODO