NAME
Net::CampaignMonitor - A Perl wrapper to the Campaign Monitor API.
VERSION
This documentation refers to version 0.01.
SYNOPSIS
use Net::CampaignMonitor;
my $cm = Net::CampaignMonitor->new({
api_key => 'abcd1234abcd1234abcd1234',
secure => 1,
timeout => 300,
});
DESCRIPTION
Net::CampaignMonitor provides a Perl wrapper to the Campaign Monitor API (v3).
METHODS
All methods return a hash containing the Campaign Monitor response code, the headers and the actual response.
my %results = (
code => '',
response => '',
headers => ''
);
Construction and setup
new
my $cm = Net::CampaignMonitor->new({
api_key => 'abcd1234abcd1234abcd1234',
secure => 1,
timeout => 300,
});
Construct a new Net::CampaignMonitor object. Takes an optional hash reference of config options. The options are:
api_key - The api key for the Campaign Monitor account. If none is supplied the only function which will work is account_apikey.
secure - Set to 1 (secure) or 0 (insecure) to determine whether to use http or https. Defaults to secure.
timeout - Set the timeout for the authentication. Defaults to 600 seconds.
account_clients
my $clients = $cm->account_clients();
my $client = $cm->account_clients((
'CompanyName' => "ACME Limited",
'ContactName' => "John Doe",
'EmailAddress' => "john\@example.com",
'Country' => "Australia",
'TimeZone' => "(GMT+10:00) Canberra, Melbourne, Sydney"
));
account_apikey
my $apikey = $cm->account_apikey($siteurl, $username, $password)
account_countries
my $countries = $cm->account_countries();
account_timezones
my $timezones = $cm->account_timezones();
account_systemdate
my $systemdate = $cm->account_systemdate();
campaigns
my $campaign = $cm->campaigns((
'clientid' => 'b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2',
'ListIDs' => [
'a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1',
'a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1'
],
'FromName' => 'My Name',
'TextUrl' => 'http://example.com/campaigncontent/index.txt',
'Subject' => 'My Subject',
'HtmlUrl' => 'http://example.com/campaigncontent/index.html',
'SegmentIDs' => [
'a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1',
'a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1'
],
'FromEmail' => 'myemail@mydomain.com',
'Name' => 'My Campaign Name',
'ReplyTo' => 'myemail@mydomain.com',
));
The clientid must be in the hash.
campaigns_send
my $send_campaign = $cm->campaigns_send((
'campaignid' => 'b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2',
'SendDate' => 'YYYY-MM-DD HH:MM',
'ConfirmationEmail' => 'myemail@mydomain.com',
));
The campaignid must be in the hash.
campaigns_sendpreview
my $send_preview_campaign = $cm->campaigns_sendpreview(
'campaignid' => $campaign_id,
'PreviewRecipients' => [
'test1@example.com',
'test2@example.com'
],
'Personalize' => 'Random',
));
The campaignid must be in the hash.
campaigns_summary
my $campaign_summary = $cm->campaigns_summary($campaign_id);
campaigns_listsandsegments
my $campaign_listsandsegments = $cm->campaigns_listsandsegments($campaign_id);
campaigns_recipients
my $campaign_recipients = $cm->campaigns_recipients (
'campaignid' => $campaign_id,
'page' => '1',
'pagesize' => '100',
'orderfield' => 'email',
'orderdirection' => 'asc',
));
campaigns_bounces
my $campaign_bounces = $cm->campaigns_bounces (
'campaignid' => $campaign_id,
'page' => '1',
'pagesize' => '100',
'orderfield' => 'email',
'orderdirection' => 'asc',
));
campaigns_opens
my $campaign_opens = $cm->campaigns_opens (
'campaignid' => $campaign_id,
'date' => '1900-01-01',
'page' => '1',
'pagesize' => '100',
'orderfield' => 'email',
'orderdirection' => 'asc',
));
campaigns_clicks
my $campaign_clicks = $cm->campaigns_clicks (
'campaignid' => $campaign_id,
'date' => '1900-01-01',
'page' => '1',
'pagesize' => '100',
'orderfield' => 'email',
'orderdirection' => 'asc',
));
campaigns_unsubscribes
my $campaign_unsubscribes = $cm->campaigns_unsubscribes (
'campaignid' => $campaign_id,
'date' => '1900-01-01',
'page' => '1',
'pagesize' => '100',
'orderfield' => 'email',
'orderdirection' => 'asc',
));
campaigns_delete
my $campaign_delete = $cm->campaigns_delete($campaign_id);
client_clientid
my $client_details = $cm->client_clientid($client_id);
client_campaigns
my $client_campaigns = $cm->client_campaigns($client_id);
client_drafts
my $client_drafts = $cm->client_drafts($client_id);
client_lists
my $client_lists = $cm->client_lists($client_id);
client_segments
my $client_segments = $cm->client_segments($client_id);
client_suppressionlist
my $client_suppressionlist = $cm->client_suppressionlist((
'clientid' => $client_id,
'page' => '1',
'pagesize' => '100',
'orderfield' => 'email',
'orderdirection' => 'asc',
));
client_templates
my $client_templates = $cm->client_templates($client_id);
client_setbasics
my $client_basic_details = $cm->client_setbasics((
'clientid' => $client_id,
'CompanyName' => "ACME Limited",
'ContactName' => "John Doe",
'EmailAddress' => "john\@example.com",
'Country' => "Australia",
'TimeZone' => "(GMT+10:00) Canberra, Melbourne, Sydney",
));
client_setaccess
Changing access level only
my $client_access-settings = $cm->client_setaccess((
'clientid' => $client_id,
'AccessLevel' => '23',
));
Setting username and password
my $client_access-settings = $cm->client_setaccess((
'clientid' => $client_id,
'AccessLevel' => '23',
'Username' => 'jdoe',
'Password' => 'password',
));
client_setpaygbilling
my $client_payg = $cm->client_setpaygbilling((
'clientid' => $client_id,
'Currency' => 'AUD',
'CanPurchaseCredits' => 'false',
'ClientPays' => 'true',
'MarkupPercentage' => '20',
'MarkupOnDelivery' => '5',
'MarkupPerRecipient' => '4',
'MarkupOnDesignSpamTest' => '3',
));
client_setmonthlybilling
my $client_monthly = $cm->client_setmonthlybilling((
'clientid' => $client_id,
'Currency' => 'AUD',
'ClientPays' => 'true',
'MarkupPercentage' => '20',
));
client_delete
my $client_deleted = $cm->client_delete($client_id);
lists
my $list = $cm->lists((
'clientid' => $client_id,
'Title' => 'Website Subscribers',
'UnsubscribePage' => 'http://www.example.com/unsubscribed.html',
'ConfirmedOptIn' => 'false',
'ConfirmationSuccessPage' => 'http://www.example.com/joined.html',
));
list_listid
my $list = $cm->list_listid($list_id);
my $updated_list = $cm->list_listid((
'listid' => $list_id,
'Title' => 'Website Subscribers',
'UnsubscribePage' => 'http://www.example.com/unsubscribed.html',
'ConfirmedOptIn' => 'false',
'ConfirmationSuccessPage' => 'http://www.example.com/joined.html',
));
list_stats
my $list_stats = $cm->list_stats($list_id);
list_customfields
my $list_customfields = $cm->list_customfields($list_id);
list_segments
my $list_segments = $cm->list_segments($list_id);
list_active
my $list_active_subscribers = $cm->list_active((
'listid' => $list_id,
'date' => '1900-01-01',
'page' => '1',
'pagesize' => '100',
'orderfield' => 'email',
'orderdirection' => 'asc',
));
list_unsubscribed
my $list_unsubscribed_subscribers = $cm->list_unsubscribed((
'listid' => $list_id,
'date' => '1900-01-01',
'page' => '1',
'pagesize' => '100',
'orderfield' => 'email',
'orderdirection' => 'asc',
));
list_bounced
my $list_bounced_subscribers = $cm->list_bounced((
'listid' => $list_id,
'date' => '1900-01-01',
'page' => '1',
'pagesize' => '100',
'orderfield' => 'email',
'orderdirection' => 'asc',
));
list_customfields
my $custom_field = $cm->list_customfields((
'listid' => $list_id,
'FieldName' => 'Newsletter Format',
'DataType' => 'MultiSelectOne',
'Options' => [ "HTML", "Text" ],
));
list_options
my $updated_options = $cm->list_options((
'listid' => $list_id,
'KeepExistingOptions' => 'true',
'Options' => [ "First Option", "Second Option", "Third Option" ],
'customfieldkey' => '[NewsletterFormat]',
));
list_delete_customfieldkey
my $deleted_customfield = $cm->list_delete_customfieldkey((
'listid' => $list_id,
'customfieldkey' => '[NewsletterFormat]',
));
list_delete
my $deleted_list = $cm->list_delete($list_id);
list_webhooks
my $webhooks = $cm->list_webhooks($list_id);
my $webhook = $cm->list_webhooks((
'listid' => $list_id,
'Events' => [ "Subscribe" ],
'Url' => 'http://example.com/subscribe',
'PayloadFormat' => 'json',
));
list_test
my $webhook = $cm->list_test((
'listid' => $list_id,
'webhookid' => $webhook_id,
));
list_delete_webhook
my $deleted_webhook = $cm->list_delete_webhook((
'listid' => $list_id,
'webhookid' => $webhook_id,
));
list_activate
my $activated_webhook = $cm->list_activate((
'listid' => $list_id,
'webhookid' => $webhook_id,
));
list_deactivate
my $deactivated_webhook = $cm->list_deactivate((
'listid' => $list_id,
'webhookid' => $webhook_id,
));
segments
my $segment = $cm->segments((
'listid' => $list_id,
'Rules' => [
{
'Subject' => 'EmailAddress',
'Clauses' => [
'CONTAINS @domain.com'
]
},
{
'Subject' => 'DateSubscribed',
'Clauses' => [
'AFTER 2009-01-01',
'EQUALS 2009-01-01'
]
},
{
'Subject' => 'DateSubscribed',
'Clauses' => [
'BEFORE 2010-01-01'
]
}
],
'Title' => 'My Segment',
));
segment_segmentid
my $updated_segment = $cm->segment_segmentid((
'segmentid' => $segment_id,
'Rules' => [
{
'Subject' => 'EmailAddress',
'Clauses' => [
'CONTAINS @domain.com'
]
},
{
'Subject' => 'DateSubscribed',
'Clauses' => [
'AFTER 2009-01-01',
'EQUALS 2009-01-01'
]
},
{
'Subject' => 'DateSubscribed',
'Clauses' => [
'BEFORE 2010-01-01'
]
}
],
'Title' => 'My Segment',
));
my $updated_segment = $cm->segment_segmentid($segment_id);
segment_rules
my $new_rules = $cm->segment_rules((
'segmentid' => $segment_id,
'Subject' => 'Name',
'Clauses' => [
'NOT_PROVIDED',
'EQUALS Subscriber Name'
],
));
segment_active
my $segment_subs = $cm->segment_active((
'segmentid' => $segment_id,
'date' => '1900-01-01',
'page' => '1',
'pagesize' => '100',
'orderfield' => 'email',
'orderdirection' => 'asc',
));
segment_delete
my $deleted_segment = $cm->segment_delete($segment_id);
segment_delete_rules
my $deleted_segment_rules = $cm->segment_delete_rules($segment_id);
subscribers
my $added_subscriber = $cm->subscribers((
'listid' => $list_id,
'Resubscribe' => 'true',
'CustomFields' => [
{
'Value' => 'http://example.com',
'Key' => 'website'
},
{
'Value' => 'magic',
'Key' => 'interests'
},
{
'Value' => 'romantic walks',
'Key' => 'interests'
}
],
'Name' => 'New Subscriber',
'EmailAddress' => 'subscriber@example.com',
));
Getting a subscriber's details
my $subs_details = $cm->subscribers((
'listid' => $list_id,
'email' => 'subscriber@example.com',
));
subscribers_import
my $imported_subs = $cm->subscribers_import((
'listid' => $list_id,
'Subscribers' => [
{
'CustomFields' => [
{
'Value' => 'http://example.com',
'Key' => 'website'
},
{
'Value' => 'magic',
'Key' => 'interests'
},
{
'Value' => 'romantic walks',
'Key' => 'interests'
}
],
'Name' => 'New Subscriber One',
'EmailAddress' => 'subscriber1@example.com'
},
{
'Name' => 'New Subscriber Two',
'EmailAddress' => 'subscriber2@example.com'
},
{
'Name' => 'New Subscriber Three',
'EmailAddress' => 'subscriber3@example.com'
}
],
'Resubscribe' => 'true',
));
subscribers_history
Getting a subscriber's history
my $subs_history = $cm->subscribers_history((
'listid' => $list_id,
'email' => 'subscriber@example.com',
));
subscribers_unsubscribe
my $unsub_sub = $cm->subscribers_unsubscribe((
'listid' => $list_id,
'EmailAddress' => 'subscriber@example.com',
));
templates
my $template = $cm->templates($template_id);
my $template = $cm->templates((
'clientid' => $client_id
'ZipFileURL' => 'http://example.com/files.zip',
'HtmlPageURL' => 'http://example.com/index.html',
'ScreenshotURL' => 'http://example.com/screenshot.jpg',
'Name' => 'Template Two',
));
my $updated_template = $cm->templates(
'templateid' => $template_id
'ZipFileURL' => 'http://example.com/files.zip',
'HtmlPageURL' => 'http://example.com/index.html',
'ScreenshotURL' => 'http://example.com/screenshot.jpg',
'Name' => 'Template Two',
));
templates_delete
my $deleted_template = $cm->templates_delete($template_id);
INSTALLATION NOTES
In order to run the full test suite you will need to provide an API Key. This can be done in the following way.
cpan CAMPAIGN_MONITOR_API_KEY=<your_api_key> Net::CampaignMonitor
If you do not do this almost all of the tests will be skipped.
BUGS
Not quite a bug. This module uses REST::Client. REST::Client fails to install properly on Windows due to this bug. You will need to make REST::Client install without running tests to install it.
AUTHOR
Jeffery Candiloro <jeffery@cpan.org>
COPYRIGHT
Copyright 2011 Jeffery Candiloro
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.