PHP Class CampaignMonitor

Inheritance: extends CampaignMonitor_API
Datei anzeigen Open project: forkcms/forkcms Class Usage Examples

Public Methods

Method Description
__construct ( string $URL, string $username, string $password, integer $timeOut = 60, null $clientId = null, null $listId = null )
addSubscriber ( string $email, string $name, array[optional] $customFields = [], bool[optional] $resubscribe = true, string[optional] $listId = null ) : boolean Adds a subscriber to an existing subscriber list. If $resubscribe is set to true, it will resubscribe the e-mail address if not active.
createCampaign ( string $name, string $subject, string $fromName, string $fromEmail, string $replyToEmail, string $HTMLContentURL, string $textContentURL, array $subscriberLists, array $subscriberListSegments = [], string[optional] $clientId = null ) : string Creates a campaign. Returns the campaign ID when succesful or false if the call failed
createClient ( string $companyName, string $country, string $timezone ) : string Creates a client. Returns the client ID when succesful or false if the call failed
createCustomField ( string $name, string[optional] $type = 'text', array[optional] $options = [], string[optional] $listId = null ) : boolean Creates a custom field for a list.
createList ( string $title, string[optional] $unsubscribePage = null, bool[optional] $confirmOptIn = false, string[optional] $confirmationSuccessPage = null, string[optional] $clientId = null ) : string Creates a list. Returns the list ID when succesful or false if the call failed
createSegment ( string $title, array[optional] $rules = [], string[optional] $listId = null ) : boolean Creates a segment. Returns true on success
createTemplate ( string $name, string $HTMLPageURL, string[optional] $zipFileURL = null, string[optional] $screenshotURL = null, string[optional] $clientId = null ) : string Creates a template. Returns the template ID when succesful
deleteCampaign ( string $campaignId ) : boolean Deletes a campaign
deleteClient ( string[optional] $clientId = null ) : boolean Deletes a client
deleteCustomField ( string $name, string[optional] $listId = null ) : boolean Deletes a custom field
deleteList ( string $listId ) : boolean Deletes a list
deleteTemplate ( string $templateId ) : boolean Deletes a template
existsClient ( string $clientId ) : boolean Checks if a client exists
existsList ( string $listId ) : boolean Checks if a list exists
existsTemplate ( string $templateId ) : boolean Checks if a template exists
getAPIKey ( string $URL, string $username, string $password ) : string Returns the API key for the logged-in user
getBouncedSubscribers ( string[optional] $listId = null, int[optional] $timestamp = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'date', string[optional] $orderDirection = 'asc' ) : array Returns a list of all subscribers for a list that have hard bounced since the specified date.
getCampaignBounces ( string $campaignId, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'date', string[optional] $orderDirection = 'asc' ) : array Returns a list of all subscribers who bounced for a given campaign, and the type of bounce ("Hard"=Hard Bounce, "Soft"=Soft Bounce).
getCampaignClicks ( string $campaignId, int[optional] $timestamp = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'date', string[optional] $orderDirection = 'asc' ) : array Contains a paged result representing all subscribers who clicked a link in the email for a given campaign, including the date/time and IP address they clicked the campaign from. The result set is organized by URL.
getCampaignOpens ( string $campaignId, int[optional] $timestamp = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'date', string[optional] $orderDirection = 'asc' ) : array Returns a list of all subscribers who opened a given campaign, and the number of times they opened the campaign
getCampaignSummary ( string $campaignId ) : array Provides a basic summary of the results for any sent campaign such as the number of recipients, opens, clicks, unsubscribes, etc to date. Also includes the URL of the web version of that campaign.
getCampaignUnsubscribes ( string $campaignId, int[optional] $timestamp = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'date', string[optional] $orderDirection = 'asc' ) : array Returns a list of all subscribers who unsubscribed for a given campaign.
getClient ( string[optional] $clientId = null ) : array Returns the complete account and billing details for a particular client.
getClientId ( ) : string Returns the default set client ID
getClients ( ) : array Returns all clients for the logged-in user.
getCountries ( ) : array Returns all countries for the logged-in user.
getCustomFields ( string[optional] $listId = null ) : array Returns all the custom fields available for a list.
getDraftCampaignsByClientID ( string[optional] $clientId = null ) : array Returns a list of all draft campaigns for a client
getList ( string[optional] $listId = null ) : array Returns a list's configuration detail
getListId ( ) : string Returns the default set list ID
getListStatistics ( string[optional] $listId = null ) : array Returns the list stats
getListsByCampaignId ( string $campaignId ) : array Returns a list of all subscriber lists for a campaign.
getListsByClientId ( string[optional] $clientId = null ) : array Returns a list of all subscriber lists for a client.
getResponseFormat ( ) : string Get response format
getSegmentsByCampaignId ( string $campaignId ) : array Returns a list of all segments for a campaign.
getSentCampaignsByClientID ( string[optional] $clientId = null ) : array Returns a list of all campaigns that have been sent for a client
getSubscriber ( string $email, string[optional] $listId = null ) : array Returns the details of a particular subscriber, including email address, name, active/inactive status and all custom field data. If a subscriber with that email address does not exist in that list, an empty record is returned.
getSubscribers ( string[optional] $listId = null, int[optional] $timestamp = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'date', string[optional] $orderDirection = 'asc' ) : array Returns a list of all active subscribers for a list that have been added since the specified date.
getSuppressionListByClientId ( string[optional] $clientId = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'email', string[optional] $orderDirection = 'asc' ) : array Returns all subscribers in the client-wide suppression list.
getSystemDate ( ) : string Returns the server system time for the logged-in user's time zone.
getTemplate ( string $templateId ) : array Returns a template's configuration detail
getTemplates ( string[optional] $clientId = null ) : array Returns a list of all templates for a client.
getTimeOut ( ) : integer Get the timeout
getTimezones ( ) : array Returns all timezones for the logged-in user.
getUnsubscribes ( string[optional] $listId = null, int[optional] $timestamp = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'email', string[optional] $orderDirection = 'asc' ) : array Contains a paged result representing all the unsubscribed subscribers for a given list. This includes their email address, name, date unsubscribed and any custom field data. You have complete control over how results should be returned including page sizes, sort order and sort direction.
getUserAgent ( ) : string Get the useragent that will be used. Our version will be prepended to yours.
importSubscribers ( array $subscribers, string[optional] $listId = null ) : array Imports "many" (CM only allows 100 max for this method) subscribers. Returns the rows that did not import.
sendCampaign ( string $campaignId, string $confirmationEmail, string[optional] $deliveryDate = null ) : string Schedules an existing campaign for sending. The campaign must be imported with defined recipients. For campaigns with more than 5 recipients the user must have sufficient credits or their credit card details saved within the application for the campaign to be sent via the API. For campaigns with 5 recipients or less the user must have enough test campaigns remaining in their API account.
sendCampaignPreview ( string $campaignId, string $recipients, string[optional] $personalization = 'Fallback' ) : string This sends a preview campaign based for a given campaign ID.
setClientId ( string $id ) Set the default client ID to use
setListId ( string $id ) Set the default list ID to use
setResponseFormat ( string[optional] $format = 'json' ) Set response format
setSiteURL ( string $siteURL ) Set the site URL
subscribe ( string $email, string[optional] $name = null, array[optional] $customFields = [], $resubscribe = true, string $listId = null ) : boolean Adds a subscriber to an existing subscriber list. If $resubscribe is set to true, it will resubscribe the email in question if it's not active in the list
unsubscribe ( string $email, string[optional] $listId = null ) : string Changes the status of an Active Subscriber to an Unsubscribed Subscriber who will no longer receive campaigns sent to that Subscriber List.
updateClientBasics ( string $companyName, string $country, string $timezone, string[optional] $clientId = null ) : string Updates a client's basic settings.
updateList ( string $title, string[optional] $unsubscribePage = null, bool[optional] $confirmOptIn = false, string[optional] $confirmationSuccessPage = null, string[optional] $listId = null ) : string Updates a subscriber list's details.
updateTemplate ( string $templateId, string[optional] $name = null, string[optional] $HTMLPageURL = null, string[optional] $zipFileURL = null, string[optional] $screenshotURL = null ) : boolean Updates a template.

Private Methods

Method Description
doCall ( string $url, array $parameters = null, string | boolean $method = 'GET', bool[optional] $secure = false, bool[optional] $expectJSON = true, bool[optional] $returnHeaders = false ) : string Make the call
getPassword ( ) : string Get the password
getSiteURL ( ) : string Set the site URL
getUsername ( ) : string Returns the username
setAPIKey ( string $key ) : void Set API key
setPassword ( string $password ) Set password
setTimeOut ( integer $seconds ) Set the timeout
setUsername ( string $username ) Set username

Method Details

__construct() public method

public __construct ( string $URL, string $username, string $password, integer $timeOut = 60, null $clientId = null, null $listId = null )
$URL string The base URL of your CreateSend site. e.g. http://example.createsend.com/.
$username string The username you use to login to Campaign Monitor.
$password string The password you use to login to Campaign Monitor.
$timeOut integer The default timeout
$clientId null The default client ID to use throughout the class.
$listId null The default list ID to use throughout the class.

addSubscriber() public method

Adds a subscriber to an existing subscriber list. If $resubscribe is set to true, it will resubscribe the e-mail address if not active.
public addSubscriber ( string $email, string $name, array[optional] $customFields = [], bool[optional] $resubscribe = true, string[optional] $listId = null ) : boolean
$email string The email address of the new subscriber.
$name string The name of the new subscriber. If the name is unknown, an empty string can be passed in.
$customFields array[optional]
$resubscribe bool[optional]
$listId string[optional]
return boolean

createCampaign() public method

Creates a campaign. Returns the campaign ID when succesful or false if the call failed
public createCampaign ( string $name, string $subject, string $fromName, string $fromEmail, string $replyToEmail, string $HTMLContentURL, string $textContentURL, array $subscriberLists, array $subscriberListSegments = [], string[optional] $clientId = null ) : string
$name string The name of the new campaign. This must be unique across all draft campaigns for the client.
$subject string The subject of the new campaign.
$fromName string The name to appear in the From field in the recipients email client when they receive the new campaign.
$fromEmail string The email address that the new campaign will come from.
$replyToEmail string The email address that any replies to the new campaign will be sent to.
$HTMLContentURL string The URL of the HTML content for the new campaign.
$textContentURL string The URL of the text content for the new campaign.
$subscriberLists array An array of lists to send the campaign to.
$subscriberListSegments array An array of Segment Names and their appropriate List ID’s to send the campaign to.
$clientId string[optional]
return string

createClient() public method

Creates a client. Returns the client ID when succesful or false if the call failed
public createClient ( string $companyName, string $country, string $timezone ) : string
$companyName string The client company name.
$country string This client’s country.
$timezone string Client timezone for tracking and reporting data.
return string

createCustomField() public method

Creates a custom field for a list.
public createCustomField ( string $name, string[optional] $type = 'text', array[optional] $options = [], string[optional] $listId = null ) : boolean
$name string The name of the field.
$type string[optional]
$options array[optional]
$listId string[optional]
return boolean

createList() public method

Creates a list. Returns the list ID when succesful or false if the call failed
public createList ( string $title, string[optional] $unsubscribePage = null, bool[optional] $confirmOptIn = false, string[optional] $confirmationSuccessPage = null, string[optional] $clientId = null ) : string
$title string The title of the list.
$unsubscribePage string[optional]
$confirmOptIn bool[optional]
$confirmationSuccessPage string[optional]
$clientId string[optional]
return string

createSegment() public method

Creates a segment. Returns true on success
public createSegment ( string $title, array[optional] $rules = [], string[optional] $listId = null ) : boolean
$title string
$rules array[optional]
$listId string[optional]
return boolean

createTemplate() public method

Creates a template. Returns the template ID when succesful
public createTemplate ( string $name, string $HTMLPageURL, string[optional] $zipFileURL = null, string[optional] $screenshotURL = null, string[optional] $clientId = null ) : string
$name string The name of the template. Maximum of 30 characters (will be truncated to 30 characters if longer).
$HTMLPageURL string The URL of the HTML page you have created for the template.
$zipFileURL string[optional]
$screenshotURL string[optional]
$clientId string[optional]
return string

deleteCampaign() public method

Deletes a campaign
public deleteCampaign ( string $campaignId ) : boolean
$campaignId string The ID of the campaign.
return boolean

deleteClient() public method

Deletes a client
public deleteClient ( string[optional] $clientId = null ) : boolean
$clientId string[optional]
return boolean

deleteCustomField() public method

Deletes a custom field
public deleteCustomField ( string $name, string[optional] $listId = null ) : boolean
$name string The name of the field.
$listId string[optional]
return boolean

deleteList() public method

Deletes a list
public deleteList ( string $listId ) : boolean
$listId string The ID of the list to delete
return boolean

deleteTemplate() public method

Deletes a template
public deleteTemplate ( string $templateId ) : boolean
$templateId string The ID of the template.
return boolean

existsClient() public method

Checks if a client exists
public existsClient ( string $clientId ) : boolean
$clientId string The ID of the client.
return boolean

existsList() public method

Checks if a list exists
public existsList ( string $listId ) : boolean
$listId string The ID of the list.
return boolean

existsTemplate() public method

Checks if a template exists
public existsTemplate ( string $templateId ) : boolean
$templateId string The ID of the template.
return boolean

getAPIKey() public method

Returns the API key for the logged-in user
public getAPIKey ( string $URL, string $username, string $password ) : string
$URL string The base URL of your CreateSend site. e.g. http://example.createsend.com/
$username string The CM account username.
$password string The CM account password.
return string

getBouncedSubscribers() public method

Returns a list of all subscribers for a list that have hard bounced since the specified date.
public getBouncedSubscribers ( string[optional] $listId = null, int[optional] $timestamp = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'date', string[optional] $orderDirection = 'asc' ) : array
$listId string[optional]
$timestamp int[optional]
$page int[optional]
$pageSize int[optional]
$orderField string[optional]
$orderDirection string[optional]
return array

getCampaignBounces() public method

Returns a list of all subscribers who bounced for a given campaign, and the type of bounce ("Hard"=Hard Bounce, "Soft"=Soft Bounce).
public getCampaignBounces ( string $campaignId, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'date', string[optional] $orderDirection = 'asc' ) : array
$campaignId string The ID of the campaign you want data for.
$page int[optional]
$pageSize int[optional]
$orderField string[optional]
$orderDirection string[optional]
return array

getCampaignClicks() public method

Contains a paged result representing all subscribers who clicked a link in the email for a given campaign, including the date/time and IP address they clicked the campaign from. The result set is organized by URL.
public getCampaignClicks ( string $campaignId, int[optional] $timestamp = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'date', string[optional] $orderDirection = 'asc' ) : array
$campaignId string The ID of the campaign you want data for.
$timestamp int[optional]
$page int[optional]
$pageSize int[optional]
$orderField string[optional]
$orderDirection string[optional]
return array

getCampaignOpens() public method

Returns a list of all subscribers who opened a given campaign, and the number of times they opened the campaign
public getCampaignOpens ( string $campaignId, int[optional] $timestamp = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'date', string[optional] $orderDirection = 'asc' ) : array
$campaignId string The ID of the campaign you want data for.
$timestamp int[optional]
$page int[optional]
$pageSize int[optional]
$orderField string[optional]
$orderDirection string[optional]
return array

getCampaignSummary() public method

Provides a basic summary of the results for any sent campaign such as the number of recipients, opens, clicks, unsubscribes, etc to date. Also includes the URL of the web version of that campaign.
public getCampaignSummary ( string $campaignId ) : array
$campaignId string The ID of the campaign you want data for.
return array

getCampaignUnsubscribes() public method

Returns a list of all subscribers who unsubscribed for a given campaign.
public getCampaignUnsubscribes ( string $campaignId, int[optional] $timestamp = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'date', string[optional] $orderDirection = 'asc' ) : array
$campaignId string The ID of the campaign you want data for.
$timestamp int[optional]
$page int[optional]
$pageSize int[optional]
$orderField string[optional]
$orderDirection string[optional]
return array

getClient() public method

Returns the complete account and billing details for a particular client.
public getClient ( string[optional] $clientId = null ) : array
$clientId string[optional]
return array

getClientId() public method

Returns the default set client ID
public getClientId ( ) : string
return string

getClients() public method

Returns all clients for the logged-in user.
public getClients ( ) : array
return array

getCountries() public method

Returns all countries for the logged-in user.
public getCountries ( ) : array
return array

getCustomFields() public method

Returns all the custom fields available for a list.
public getCustomFields ( string[optional] $listId = null ) : array
$listId string[optional]
return array

getDraftCampaignsByClientID() public method

Returns a list of all draft campaigns for a client
public getDraftCampaignsByClientID ( string[optional] $clientId = null ) : array
$clientId string[optional]
return array

getList() public method

Returns a list's configuration detail
public getList ( string[optional] $listId = null ) : array
$listId string[optional]
return array

getListId() public method

Returns the default set list ID
public getListId ( ) : string
return string

getListStatistics() public method

Returns the list stats
public getListStatistics ( string[optional] $listId = null ) : array
$listId string[optional]
return array

getListsByCampaignId() public method

Returns a list of all subscriber lists for a campaign.
public getListsByCampaignId ( string $campaignId ) : array
$campaignId string The ID of the campaign.
return array

getListsByClientId() public method

Returns a list of all subscriber lists for a client.
public getListsByClientId ( string[optional] $clientId = null ) : array
$clientId string[optional]
return array

getResponseFormat() public method

Get response format
public getResponseFormat ( ) : string
return string

getSegmentsByCampaignId() public method

Returns a list of all segments for a campaign.
public getSegmentsByCampaignId ( string $campaignId ) : array
$campaignId string The ID of the campaign.
return array

getSentCampaignsByClientID() public method

Returns a list of all campaigns that have been sent for a client
public getSentCampaignsByClientID ( string[optional] $clientId = null ) : array
$clientId string[optional]
return array

getSubscriber() public method

Returns the details of a particular subscriber, including email address, name, active/inactive status and all custom field data. If a subscriber with that email address does not exist in that list, an empty record is returned.
public getSubscriber ( string $email, string[optional] $listId = null ) : array
$email string The emailaddress.
$listId string[optional]
return array

getSubscribers() public method

http://www.campaignmonitor.com/api/lists/#getting_active_subscribers
public getSubscribers ( string[optional] $listId = null, int[optional] $timestamp = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'date', string[optional] $orderDirection = 'asc' ) : array
$listId string[optional]
$timestamp int[optional]
$page int[optional]
$pageSize int[optional]
$orderField string[optional]
$orderDirection string[optional]
return array

getSuppressionListByClientId() public method

Returns all subscribers in the client-wide suppression list.
public getSuppressionListByClientId ( string[optional] $clientId = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'email', string[optional] $orderDirection = 'asc' ) : array
$clientId string[optional]
$page int[optional]
$pageSize int[optional]
$orderField string[optional]
$orderDirection string[optional]
return array

getSystemDate() public method

Returns the server system time for the logged-in user's time zone.
public getSystemDate ( ) : string
return string

getTemplate() public method

Returns a template's configuration detail
public getTemplate ( string $templateId ) : array
$templateId string The ID of the template.
return array

getTemplates() public method

http://www.campaignmonitor.com/api/clients/#getting_client_templates
public getTemplates ( string[optional] $clientId = null ) : array
$clientId string[optional]
return array

getTimeOut() public method

Get the timeout
public getTimeOut ( ) : integer
return integer

getTimezones() public method

Returns all timezones for the logged-in user.
public getTimezones ( ) : array
return array

getUnsubscribes() public method

Contains a paged result representing all the unsubscribed subscribers for a given list. This includes their email address, name, date unsubscribed and any custom field data. You have complete control over how results should be returned including page sizes, sort order and sort direction.
public getUnsubscribes ( string[optional] $listId = null, int[optional] $timestamp = null, int[optional] $page = 1, int[optional] $pageSize = 1000, string[optional] $orderField = 'email', string[optional] $orderDirection = 'asc' ) : array
$listId string[optional]
$timestamp int[optional]
$page int[optional]
$pageSize int[optional]
$orderField string[optional]
$orderDirection string[optional]
return array

getUserAgent() public method

It will look like: "PHP CampaignMonitor/ "
public getUserAgent ( ) : string
return string

importSubscribers() public method

Imports "many" (CM only allows 100 max for this method) subscribers. Returns the rows that did not import.
public importSubscribers ( array $subscribers, string[optional] $listId = null ) : array
$subscribers array
$listId string[optional]
return array The failed results.

sendCampaign() public method

Schedules an existing campaign for sending. The campaign must be imported with defined recipients. For campaigns with more than 5 recipients the user must have sufficient credits or their credit card details saved within the application for the campaign to be sent via the API. For campaigns with 5 recipients or less the user must have enough test campaigns remaining in their API account.
public sendCampaign ( string $campaignId, string $confirmationEmail, string[optional] $deliveryDate = null ) : string
$campaignId string The ID of the campaign to send.
$confirmationEmail string The email address where the confirmation email will be sent to.
$deliveryDate string[optional]
return string

sendCampaignPreview() public method

This sends a preview campaign based for a given campaign ID.
public sendCampaignPreview ( string $campaignId, string $recipients, string[optional] $personalization = 'Fallback' ) : string
$campaignId string The ID of the campaign to send.
$recipients string This can be an e-mail address string, or an array of addresses.
$personalization string[optional]
return string

setClientId() public method

Set the default client ID to use
public setClientId ( string $id )
$id string

setListId() public method

Set the default list ID to use
public setListId ( string $id )
$id string

setResponseFormat() public method

Set response format
public setResponseFormat ( string[optional] $format = 'json' )
$format string[optional]

setSiteURL() public method

Set the site URL
public setSiteURL ( string $siteURL )
$siteURL string The base URL of the site you use to login to Campaign Monitor. e.g. http://example.createsend.com/

subscribe() public method

Adds a subscriber to an existing subscriber list. If $resubscribe is set to true, it will resubscribe the email in question if it's not active in the list
public subscribe ( string $email, string[optional] $name = null, array[optional] $customFields = [], $resubscribe = true, string $listId = null ) : boolean
$email string The email address of the new subscriber.
$name string[optional]
$customFields array[optional]
$listId string
return boolean

unsubscribe() public method

Changes the status of an Active Subscriber to an Unsubscribed Subscriber who will no longer receive campaigns sent to that Subscriber List.
public unsubscribe ( string $email, string[optional] $listId = null ) : string
$email string The emailaddress.
$listId string[optional]
return string

updateClientBasics() public method

Updates a client's basic settings.
public updateClientBasics ( string $companyName, string $country, string $timezone, string[optional] $clientId = null ) : string
$companyName string The client company name.
$country string This client's country.
$timezone string Client timezone for tracking and reporting data.
$clientId string[optional]
return string

updateList() public method

Updates a subscriber list's details.
public updateList ( string $title, string[optional] $unsubscribePage = null, bool[optional] $confirmOptIn = false, string[optional] $confirmationSuccessPage = null, string[optional] $listId = null ) : string
$title string The title of the list.
$unsubscribePage string[optional]
$confirmOptIn bool[optional]
$confirmationSuccessPage string[optional]
$listId string[optional]
return string

updateTemplate() public method

Updates a template.
public updateTemplate ( string $templateId, string[optional] $name = null, string[optional] $HTMLPageURL = null, string[optional] $zipFileURL = null, string[optional] $screenshotURL = null ) : boolean
$templateId string The ID of the template.
$name string[optional]
$HTMLPageURL string[optional]
$zipFileURL string[optional]
$screenshotURL string[optional]
return boolean