PageRenderTime 60ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_breezingforms/libraries/mailchimp/MCAPI.class.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip
PHP | 1814 lines | 553 code | 90 blank | 1171 comment | 24 complexity | a37c7561e52348b21672e52378a0e55d MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, JSON, GPL-2.0, BSD-3-Clause, LGPL-2.1, MIT
  1. <?php
  2. defined('_JEXEC') or die('Direct Access to this location is not allowed.');
  3. /**
  4. * BreezingForms - A Joomla Forms Application
  5. * @version 1.8
  6. * @package BreezingForms
  7. * @copyright (C) 2008-2012 by Markus Bopp
  8. * @license Released under the terms of the GNU General Public License
  9. **/
  10. class MCAPI {
  11. var $version = "1.2";
  12. var $errorMessage;
  13. var $errorCode;
  14. /**
  15. * Cache the information on the API location on the server
  16. */
  17. var $apiUrl;
  18. /**
  19. * Default to a 300 second timeout on server calls
  20. */
  21. var $timeout = 300;
  22. /**
  23. * Default to a 8K chunk size
  24. */
  25. var $chunkSize = 8192;
  26. /**
  27. * Cache the user api_key so we only have to log in once per client instantiation
  28. */
  29. var $api_key;
  30. /**
  31. * Cache the user api_key so we only have to log in once per client instantiation
  32. */
  33. var $secure = false;
  34. /**
  35. * Connect to the MailChimp API for a given list.
  36. *
  37. * @param string $apikey Your MailChimp apikey
  38. * @param string $secure Whether or not this should use a secure connection
  39. */
  40. function MCAPI($apikey, $secure=false) {
  41. //do more "caching" of the uuid for those people that keep instantiating this...
  42. $this->secure = $secure;
  43. $this->apiUrl = parse_url("http://api.mailchimp.com/" . $this->version . "/?output=php");
  44. if ( isset($GLOBALS["mc_api_key"]) && $GLOBALS["mc_api_key"]!="" ){
  45. $this->api_key = $GLOBALS["mc_api_key"];
  46. } else {
  47. $this->api_key = $GLOBALS["mc_api_key"] = $apikey;
  48. }
  49. }
  50. function setTimeout($seconds){
  51. if (is_int($seconds)){
  52. $this->timeout = $seconds;
  53. return true;
  54. }
  55. }
  56. function getTimeout(){
  57. return $this->timeout;
  58. }
  59. function useSecure($val){
  60. if ($val===true){
  61. $this->secure = true;
  62. } else {
  63. $this->secure = false;
  64. }
  65. }
  66. /**
  67. * Unschedule a campaign that is scheduled to be sent in the future
  68. *
  69. * @section Campaign Related
  70. * @example mcapi_campaignUnschedule.php
  71. * @example xml-rpc_campaignUnschedule.php
  72. *
  73. * @param string $cid the id of the campaign to unschedule
  74. * @return boolean true on success
  75. */
  76. function campaignUnschedule($cid) {
  77. $params = array();
  78. $params["cid"] = $cid;
  79. return $this->callServer("campaignUnschedule", $params);
  80. }
  81. /**
  82. * Schedule a campaign to be sent in the future
  83. *
  84. * @section Campaign Related
  85. * @example mcapi_campaignSchedule.php
  86. * @example xml-rpc_campaignSchedule.php
  87. *
  88. * @param string $cid the id of the campaign to schedule
  89. * @param string $schedule_time the time to schedule the campaign. For A/B Split "schedule" campaigns, the time for Group A - in YYYY-MM-DD HH:II:SS format in <strong>GMT</strong>
  90. * @param string $schedule_time_b optional -the time to schedule Group B of an A/B Split "schedule" campaign - in YYYY-MM-DD HH:II:SS format in <strong>GMT</strong>
  91. * @return boolean true on success
  92. */
  93. function campaignSchedule($cid, $schedule_time, $schedule_time_b=NULL) {
  94. $params = array();
  95. $params["cid"] = $cid;
  96. $params["schedule_time"] = $schedule_time;
  97. $params["schedule_time_b"] = $schedule_time_b;
  98. return $this->callServer("campaignSchedule", $params);
  99. }
  100. /**
  101. * Resume sending an AutoResponder or RSS campaign
  102. *
  103. * @section Campaign Related
  104. *
  105. * @param string $cid the id of the campaign to pause
  106. * @return boolean true on success
  107. */
  108. function campaignResume($cid) {
  109. $params = array();
  110. $params["cid"] = $cid;
  111. return $this->callServer("campaignResume", $params);
  112. }
  113. /**
  114. * Pause an AutoResponder orRSS campaign from sending
  115. *
  116. * @section Campaign Related
  117. *
  118. * @param string $cid the id of the campaign to pause
  119. * @return boolean true on success
  120. */
  121. function campaignPause($cid) {
  122. $params = array();
  123. $params["cid"] = $cid;
  124. return $this->callServer("campaignPause", $params);
  125. }
  126. /**
  127. * Send a given campaign immediately
  128. *
  129. * @section Campaign Related
  130. *
  131. * @example mcapi_campaignSendNow.php
  132. * @example xml-rpc_campaignSendNow.php
  133. *
  134. * @param string $cid the id of the campaign to resume
  135. * @return boolean true on success
  136. */
  137. function campaignSendNow($cid) {
  138. $params = array();
  139. $params["cid"] = $cid;
  140. return $this->callServer("campaignSendNow", $params);
  141. }
  142. /**
  143. * Send a test of this campaign to the provided email address
  144. *
  145. * @section Campaign Related
  146. *
  147. * @example mcapi_campaignSendTest.php
  148. * @example xml-rpc_campaignSendTest.php
  149. *
  150. * @param string $cid the id of the campaign to test
  151. * @param array $test_emails an array of email address to receive the test message
  152. * @param string $send_type optional by default (null) both formats are sent - "html" or "text" send just that format
  153. * @return boolean true on success
  154. */
  155. function campaignSendTest($cid, $test_emails=array (
  156. ), $send_type=NULL) {
  157. $params = array();
  158. $params["cid"] = $cid;
  159. $params["test_emails"] = $test_emails;
  160. $params["send_type"] = $send_type;
  161. return $this->callServer("campaignSendTest", $params);
  162. }
  163. /**
  164. * Retrieve all templates defined for your user account
  165. *
  166. * @section Campaign Related
  167. * @example mcapi_campaignTemplates.php
  168. * @example xml-rpc_campaignTemplates.php
  169. *
  170. * @return array An array of structs, one for each template (see Returned Fields for details)
  171. * @returnf integer id Id of the template
  172. * @returnf string name Name of the template
  173. * @returnf string layout Layout of the template - "basic", "left_column", "right_column", or "postcard"
  174. * @returnf string preview_image If we've generated it, the url of the preview image for the template
  175. * @returnf array sections associative array of editable sections in the template that can accept custom HTML when sending a campaign
  176. */
  177. function campaignTemplates() {
  178. $params = array();
  179. return $this->callServer("campaignTemplates", $params);
  180. }
  181. /**
  182. * Allows one to test their segmentation rules before creating a campaign using them
  183. *
  184. * @section Campaign Related
  185. * @example mcapi_campaignSegmentTest.php
  186. * @example xml-rpc_campaignSegmentTest.php
  187. *
  188. * @param string $list_id the list to test segmentation on - get lists using lists()
  189. * @param array $options with 2 keys:
  190. string "match" controls whether to use AND or OR when applying your options - expects "<strong>any</strong>" (for OR) or "<strong>all</strong>" (for AND)
  191. array "conditions" - up to 10 different criteria to apply while segmenting. Each criteria row must contain 3 keys - "<strong>field</strong>", "<strong>op</strong>", and "<strong>value</strong>" - and possibly a fourth, "<strong>extra</strong>", based on these definitions:
  192. Field = "<strong>date</strong>" : Select based on various dates we track
  193. Valid Op(eration): <strong>eq</strong> (is) / <strong>gt</strong> (after) / <strong>lt</strong> (before)
  194. Valid Values:
  195. string last_campaign_sent uses the date of the last campaign sent
  196. string campaign_id - uses the send date of the campaign that carriers the Id submitted - see campaigns()
  197. string YYYY-MM-DD - any date in the form of YYYY-MM-DD - <em>note:</em> anything that appears to start with YYYY will be treated as a date
  198. Field = "<strong>interests</strong>":
  199. Valid Op(erations): <strong>one</strong> / <strong>none</strong> / <strong>all</strong>
  200. Valid Values: a comma delimited of interest groups for the list - see listInterestGroups()
  201. Field = "<strong>aim</strong>"
  202. Valid Op(erations): <strong>open</strong> / <strong>noopen</strong> / <strong>click</strong> / <strong>noclick</strong>
  203. Valid Values: "<strong>any</strong>" or a valid AIM-enabled Campaign that has been sent
  204. Field = "<strong>rating</strong>" : allows matching based on list member ratings
  205. Valid Op(erations): <strong>eq</strong> (=) / <strong>ne</strong> (!=) / <strong>gt</strong> (&gt;) / <strong>lt</strong> (&lt;)
  206. Valid Values: a number between 0 and 5
  207. Field = "<strong>ecomm_prod</strong>" or "<strong>ecomm_prod</strong>": allows matching product and category names from purchases
  208. Valid Op(erations):
  209. <strong>eq</strong> (=) / <strong>ne</strong> (!=) / <strong>gt</strong> (&gt;) / <strong>lt</strong> (&lt;) / <strong>like</strong> (like '%blah%') / <strong>nlike</strong> (not like '%blah%') / <strong>starts</strong> (like 'blah%') / <strong>ends</strong> (like '%blah')
  210. Valid Values: any string
  211. Field = "<strong>ecomm_spent_one</strong>" or "<strong>ecomm_spent_all</strong>" : allows matching purchase amounts on a single order or all orders
  212. Valid Op(erations): <strong>gt</strong> (&gt;) / <strong>lt</strong> (&lt;)
  213. Valid Values: a number
  214. Field = "<strong>ecomm_date</strong>" : allow matching based on order dates
  215. Valid Op(eration): <strong>eq</strong> (is) / <strong>gt</strong> (after) / <strong>lt</strong> (before)
  216. Valid Values:
  217. string YYYY-MM-DD - any date in the form of YYYY-MM-DD
  218. Field = An <strong>Address</strong> Merge Var. Use <strong>Merge0-Merge30</strong> or the <strong>Custom Tag</strong> you've setup for your merge field - see listMergeVars(). Note, Address fields can still be used with the default operations below - this section is broken out solely to highlight the differences in using the geolocation routines.
  219. Valid Op(erations): <strong>geoin</strong>
  220. Valid Values: The number of miles an address should be within
  221. Extra Value: The Zip Code to be used as the center point
  222. Default Field = A Merge Var. Use <strong>Merge0-Merge30</strong> or the <strong>Custom Tag</strong> you've setup for your merge field - see listMergeVars()
  223. Valid Op(erations):
  224. <strong>eq</strong> (=) / <strong>ne</strong> (!=) / <strong>gt</strong> (&gt;) / <strong>lt</strong> (&lt;) / <strong>like</strong> (like '%blah%') / <strong>nlike</strong> (not like '%blah%') / <strong>starts</strong> (like 'blah%') / <strong>ends</strong> (like '%blah')
  225. Valid Values: any string
  226. * @return integer total The total number of subscribers matching your segmentation options
  227. */
  228. function campaignSegmentTest($list_id, $options) {
  229. $params = array();
  230. $params["list_id"] = $list_id;
  231. $params["options"] = $options;
  232. return $this->callServer("campaignSegmentTest", $params);
  233. }
  234. /**
  235. * Create a new draft campaign to send
  236. *
  237. * @section Campaign Related
  238. * @example mcapi_campaignCreate.php
  239. * @example xml-rpc_campaignCreate.php
  240. * @example xml-rpc_campaignCreateABSplit.php
  241. * @example xml-rpc_campaignCreateRss.php
  242. *
  243. * @param string $type the Campaign Type to create - one of "regular", "plaintext", "absplit", "rss", "trans", "auto"
  244. * @param array $options a hash of the standard options for this campaign :
  245. string list_id the list to send this campaign to- get lists using lists()
  246. string subject the subject line for your campaign message
  247. string from_email the From: email address for your campaign message
  248. string from_name the From: name for your campaign message (not an email address)
  249. string to_email the To: name recipients will see (not email address)
  250. integer template_id optional - use this template to generate the HTML content of the campaign
  251. integer folder_id optional - automatically file the new campaign in the folder_id passed
  252. array tracking optional - set which recipient actions will be tracked, as a struct of boolean values with the following keys: "opens", "html_clicks", and "text_clicks". By default, opens and HTML clicks will be tracked.
  253. string title optional - an internal name to use for this campaign. By default, the campaign subject will be used.
  254. boolean authenticate optional - set to true to enable SenderID, DomainKeys, and DKIM authentication, defaults to false.
  255. array analytics optional - if provided, use a struct with "service type" as a key and the "service tag" as a value. For Google, this should be "google"=>"your_google_analytics_key_here". Note that only "google" is currently supported - a Google Analytics tags will be added to all links in the campaign with this string attached. Others may be added in the future
  256. boolean auto_footer optional Whether or not we should auto-generate the footer for your content. Mostly useful for content from URLs or Imports
  257. boolean inline_css optional Whether or not css should be automatically inlined when this campaign is sent, defaults to false.
  258. boolean generate_text optional Whether of not to auto-generate your Text content from the HTML content. Note that this will be ignored if the Text part of the content passed is not empty, defaults to false.
  259. boolean auto_tweet optional If set, this campaign will be auto-tweeted when it is sent - defaults to false. Note that if a Twitter account isn't linked, this will be silently ignored.
  260. * @param array $content the content for this campaign - use a struct with the following keys:
  261. "html" for pasted HTML content
  262. "text" for the plain-text version
  263. "url" to have us pull in content from a URL. Note, this will override any other content options - for lists with Email Format options, you'll need to turn on generate_text as well
  264. "archive" to send a Base64 encoded archive file for us to import all media from. Note, this will override any other content options - for lists with Email Format options, you'll need to turn on generate_text as well
  265. "archive_type" optional - only necessary for the "archive" option. Supported formats are: zip, tar.gz, tar.bz2, tar, tgz, tbz . If not included, we will default to zip
  266. If you chose a template instead of pasting in your HTML content, then use "html_" followed by the template sections as keys - for example, use a key of "html_MAIN" to fill in the "MAIN" section of a template. Supported template sections include: "html_HEADER", "html_MAIN", "html_SIDECOLUMN", and "html_FOOTER"
  267. * @param array $segment_opts optional - if you wish to do Segmentation with this campaign this array should contain: see campaignSegmentTest(). It's suggested that you test your options against campaignSegmentTest(). Also, "trans" campaigns <strong>do not</strong> support segmentation.
  268. * @param array $type_opts optional -
  269. For RSS Campaigns this, array should contain:
  270. string url the URL to pull RSS content from - it will be verified and must exist
  271. string schedule optional one of "daily", "weekly", "monthly" - defaults to "daily"
  272. string schedule_hour optional an hour between 0 and 24 - default to 4 (4am <em>local time</em>) - applies to all schedule types
  273. string schedule_weekday optional for "weekly" only, a number specifying the day of the week to send: 0 (Sunday) - 6 (Saturday) - defaults to 1 (Monday)
  274. string schedule_monthday optional for "monthly" only, a number specifying the day of the month to send (1 - 28) or "last" for the last day of a given month. Defaults to the 1st day of the month
  275. For A/B Split campaigns, this array should contain:
  276. string split_test The values to segment based on. Currently, one of: "subject", "from_name", "schedule". NOTE, for "schedule", you will need to call campaignSchedule() separately!
  277. string pick_winner How the winner will be picked, one of: "opens" (by the open_rate), "clicks" (by the click rate), "manual" (you pick manually)
  278. integer wait_units optional the default time unit to wait before auto-selecting a winner - use "3600" for hours, "86400" for days. Defaults to 86400.
  279. integer wait_time optional the number of units to wait before auto-selecting a winner - defaults to 1, so if not set, a winner will be selected after 1 Day.
  280. integer split_size optional this is a percentage of what size the Campaign's List plus any segmentation options results in. "schedule" type forces 50%, all others default to 10%
  281. string from_name_a optional sort of, required when split_test is "from_name"
  282. string from_name_b optional sort of, required when split_test is "from_name"
  283. string from_email_a optional sort of, required when split_test is "from_name"
  284. string from_email_b optional sort of, required when split_test is "from_name"
  285. string subject_a optional sort of, required when split_test is "subject"
  286. string subject_b optional sort of, required when split_test is "subject"
  287. For AutoResponder campaigns, this array should contain:
  288. string offset-units one of "day", "week", "month", "year" - required
  289. string offset-time the number of units, must be a number greater than 0 - required
  290. string offset-dir either "before" or "after"
  291. string event optional "signup" (default) to base this on double-optin signup, "date" or "annual" to base this on merge field in the list
  292. string event-datemerge optional sort of, this is required if the event is "date" or "annual"
  293. *
  294. * @return string the ID for the created campaign
  295. */
  296. function campaignCreate($type, $options, $content, $segment_opts=NULL, $type_opts=NULL) {
  297. $params = array();
  298. $params["type"] = $type;
  299. $params["options"] = $options;
  300. $params["content"] = $content;
  301. $params["segment_opts"] = $segment_opts;
  302. $params["type_opts"] = $type_opts;
  303. return $this->callServer("campaignCreate", $params);
  304. }
  305. /** Update just about any setting for a campaign that has <em>not</em> been sent. See campaignCreate() for details.
  306. *
  307. *
  308. * Caveats:<br/><ul>
  309. * <li>If you set list_id, all segmentation options will be deleted and must be re-added.</li>
  310. * <li>If you set template_id, you need to follow that up by setting it's 'content'</li>
  311. * <li>If you set segment_opts, you should have tested your options against campaignSegmentTest() as campaignUpdate() will not allow you to set a segment that includes no members.</li></ul>
  312. * @section Campaign Related
  313. *
  314. * @example mcapi_campaignUpdate.php
  315. * @example mcapi_campaignUpdateAB.php
  316. * @example xml-rpc_campaignUpdate.php
  317. * @example xml-rpc_campaignUpdateAB.php
  318. *
  319. * @param string $cid the Campaign Id to update
  320. * @param string $name the parameter name ( see campaignCreate() ). For items in the <strong>options</strong> array, this will be that parameter's name (subject, from_email, etc.). Additional parameters will be that option name (content, segment_opts). "type_opts" will be the name of the type - rss, auto, trans, etc.
  321. * @param mixed $value an appropriate value for the parameter ( see campaignCreate() ). For items in the <strong>options</strong> array, this will be that parameter's value. For additional parameters, this is the same value passed to them.
  322. * @return boolean true if the update succeeds, otherwise an error will be thrown
  323. */
  324. function campaignUpdate($cid, $name, $value) {
  325. $params = array();
  326. $params["cid"] = $cid;
  327. $params["name"] = $name;
  328. $params["value"] = $value;
  329. return $this->callServer("campaignUpdate", $params);
  330. }
  331. /** Replicate a campaign.
  332. *
  333. * @section Campaign Related
  334. *
  335. * @example mcapi_campaignReplicate.php
  336. *
  337. * @param string $cid the Campaign Id to replicate
  338. * @return string the id of the replicated Campaign created, otherwise an error will be thrown
  339. */
  340. function campaignReplicate($cid) {
  341. $params = array();
  342. $params["cid"] = $cid;
  343. return $this->callServer("campaignReplicate", $params);
  344. }
  345. /** Delete a campaign. Seriously, "poof, gone!" - be careful!
  346. *
  347. * @section Campaign Related
  348. *
  349. * @example mcapi_campaignDelete.php
  350. *
  351. * @param string $cid the Campaign Id to delete
  352. * @return boolean true if the delete succeeds, otherwise an error will be thrown
  353. */
  354. function campaignDelete($cid) {
  355. $params = array();
  356. $params["cid"] = $cid;
  357. return $this->callServer("campaignDelete", $params);
  358. }
  359. /**
  360. * Get the list of campaigns and their details matching the specified filters
  361. *
  362. * @section Campaign Related
  363. * @example mcapi_campaigns.php
  364. * @example xml-rpc_campaigns.php
  365. *
  366. * @param array $filters a hash of filters to apply to this query - all are optional:
  367. string campaign_id optional - return a single campaign using a know campaign_id
  368. string list_id optional - the list to send this campaign to- get lists using lists()
  369. integer folder_id optional - only show campaigns from this folder id - get folders using campaignFolders()
  370. string status optional - return campaigns of a specific status - one of "save", "paused", "schedule", "sending"
  371. string type optional - return campaigns of a specific type - one of "regular", "plaintext", "absplit", "rss", "trans", "auto"
  372. string from_name optional - only show campaigns that have this "From Name"
  373. string from_email optional - only show campaigns that have this "Reply-to Email"
  374. string title optional - only show campaigns that have this title
  375. string subject optional - only show campaigns that have this subject
  376. string sendtime_start optional - only show campaigns that have been sent since this date/time (in GMT) - format is YYYY-MM-DD HH:mm:ss (24hr)
  377. string sendtime_end optional - only show campaigns that have been sent before this date/time (in GMT) - format is YYYY-MM-DD HH:mm:ss (24hr)
  378. boolean exact optional - flag for whether to filter on exact values when filtering, or search within content for filter values - defaults to true
  379. * @param integer $start optional - control paging of campaigns, start results at this campaign #, defaults to 1st page of data (page 0)
  380. * @param integer $limit optional - control paging of campaigns, number of campaigns to return with each call, defaults to 25 (max=1000)
  381. * @return array list of campaigns and their associated information (see Returned Fields for description)
  382. * @returnf string id Campaign Id (used for all other campaign functions)
  383. * @returnf integer web_id The Campaign id used in our web app, allows you to create a link directly to it
  384. * @returnf string title Title of the campaign
  385. * @returnf string type The type of campaign this is (regular,plaintext,absplit,rss,inspection,trans,auto)
  386. * @returnf date create_time Creation time for the campaign
  387. * @returnf date send_time Send time for the campaign - also the scheduled time for scheduled campaigns.
  388. * @returnf integer emails_sent Number of emails email was sent to
  389. * @returnf string status Status of the given campaign (save,paused,schedule,sending,sent)
  390. * @returnf string from_name From name of the given campaign
  391. * @returnf string from_email Reply-to email of the given campaign
  392. * @returnf string subject Subject of the given campaign
  393. * @returnf string to_email Custom "To:" email string using merge variables
  394. * @returnf string archive_url Archive link for the given campaign
  395. * @returnf boolean inline_css Whether or not the campaigns content auto-css-lined
  396. * @returnf string analytics Either "google" if enabled or "N" if disabled
  397. * @returnf string analytcs_tag The name/tag the campaign's links were tagged with if analytics were enabled.
  398. * @returnf boolean track_clicks_text Whether or not links in the text version of the campaign were tracked
  399. * @returnf boolean track_clicks_html Whether or not links in the html version of the campaign were tracked
  400. * @returnf boolean track_opens Whether or not opens for the campaign were tracked
  401. * @returnf string segment_text a string marked-up with HTML explaining the segment used for the campaign in plain English
  402. * @returnf array segment_opts the segment used for the campaign - can be passed to campaignSegmentTest() or campaignCreate()
  403. */
  404. function campaigns($filters=array (
  405. ), $start=0, $limit=25) {
  406. $params = array();
  407. $params["filters"] = $filters;
  408. $params["start"] = $start;
  409. $params["limit"] = $limit;
  410. return $this->callServer("campaigns", $params);
  411. }
  412. /**
  413. * List all the folders for a user account
  414. *
  415. * @section Campaign Related
  416. * @example mcapi_campaignFolders.php
  417. * @example xml-rpc_campaignFolders.php
  418. *
  419. * @return array Array of folder structs (see Returned Fields for details)
  420. * @returnf integer folder_id Folder Id for the given folder, this can be used in the campaigns() function to filter on.
  421. * @returnf string name Name of the given folder
  422. */
  423. function campaignFolders() {
  424. $params = array();
  425. return $this->callServer("campaignFolders", $params);
  426. }
  427. /**
  428. * Given a list and a campaign, get all the relevant campaign statistics (opens, bounces, clicks, etc.)
  429. *
  430. * @section Campaign Stats
  431. *
  432. * @example mcapi_campaignStats.php
  433. * @example xml-rpc_campaignStats.php
  434. *
  435. * @param string $cid the campaign id to pull stats for (can be gathered using campaigns())
  436. * @return array struct of the statistics for this campaign
  437. * @returnf integer syntax_errors Number of email addresses in campaign that had syntactical errors.
  438. * @returnf integer hard_bounces Number of email addresses in campaign that hard bounced.
  439. * @returnf integer soft_bounces Number of email addresses in campaign that soft bounced.
  440. * @returnf integer unsubscribes Number of email addresses in campaign that unsubscribed.
  441. * @returnf integer abuse_reports Number of email addresses in campaign that reported campaign for abuse.
  442. * @returnf integer forwards Number of times email was forwarded to a friend.
  443. * @returnf integer forwards_opens Number of times a forwarded email was opened.
  444. * @returnf integer opens Number of times the campaign was opened.
  445. * @returnf date last_open Date of the last time the email was opened.
  446. * @returnf integer unique_opens Number of people who opened the campaign.
  447. * @returnf integer clicks Number of times a link in the campaign was clicked.
  448. * @returnf integer unique_clicks Number of unique recipient/click pairs for the campaign.
  449. * @returnf date last_click Date of the last time a link in the email was clicked.
  450. * @returnf integer users_who_clicked Number of unique recipients who clicked on a link in the campaign.
  451. * @returnf integer emails_sent Number of email addresses campaign was sent to.
  452. */
  453. function campaignStats($cid) {
  454. $params = array();
  455. $params["cid"] = $cid;
  456. return $this->callServer("campaignStats", $params);
  457. }
  458. /**
  459. * Get an array of the urls being tracked, and their click counts for a given campaign
  460. *
  461. * @section Campaign Stats
  462. *
  463. * @example mcapi_campaignClickStats.php
  464. * @example xml-rpc_campaignClickStats.php
  465. *
  466. * @param string $cid the campaign id to pull stats for (can be gathered using campaigns())
  467. * @return struct urls will be keys and contain their associated statistics:
  468. * @returnf integer clicks Number of times the specific link was clicked
  469. * @returnf integer unique Number of unique people who clicked on the specific link
  470. */
  471. function campaignClickStats($cid) {
  472. $params = array();
  473. $params["cid"] = $cid;
  474. return $this->callServer("campaignClickStats", $params);
  475. }
  476. /**
  477. * Get the top 5 performing email domains for this campaign. Users want more than 5 should use campaign campaignEmailStatsAIM()
  478. * or campaignEmailStatsAIMAll() and generate any additional stats they require.
  479. *
  480. * @section Campaign Stats
  481. *
  482. * @example mcapi_campaignEmailDomainPerformance.php
  483. *
  484. * @param string $cid the campaign id to pull email domain performance for (can be gathered using campaigns())
  485. * @return array domains email domains and their associated stats
  486. * @returnf string domain Domain name or special "Other" to roll-up stats past 5 domains
  487. * @returnf integer total_sent Total Email across all domains - this will be the same in every row
  488. * @returnf integer emails Number of emails sent to this domain
  489. * @returnf integer bounces Number of bounces
  490. * @returnf integer opens Number of opens
  491. * @returnf integer clicks Number of clicks
  492. * @returnf integer unsubs Number of unsubs
  493. * @returnf integer delivered Number of deliveries
  494. * @returnf integer emails_pct Percentage of emails that went to this domain (whole number)
  495. * @returnf integer bounces_pct Percentage of bounces from this domain (whole number)
  496. * @returnf integer opens_pct Percentage of opens from this domain (whole number)
  497. * @returnf integer clicks_pct Percentage of clicks from this domain (whole number)
  498. * @returnf integer unsubs_pct Percentage of unsubs from this domain (whole number)
  499. */
  500. function campaignEmailDomainPerformance($cid) {
  501. $params = array();
  502. $params["cid"] = $cid;
  503. return $this->callServer("campaignEmailDomainPerformance", $params);
  504. }
  505. /**
  506. * Get all email addresses with Hard Bounces for a given campaign
  507. *
  508. * @section Campaign Stats
  509. *
  510. * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
  511. * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
  512. * @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
  513. * @return array Arrays of email addresses with Hard Bounces
  514. */
  515. function campaignHardBounces($cid, $start=0, $limit=1000) {
  516. $params = array();
  517. $params["cid"] = $cid;
  518. $params["start"] = $start;
  519. $params["limit"] = $limit;
  520. return $this->callServer("campaignHardBounces", $params);
  521. }
  522. /**
  523. * Get all email addresses with Soft Bounces for a given campaign
  524. *
  525. * @section Campaign Stats
  526. *
  527. * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
  528. * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
  529. * @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
  530. * @return array Arrays of email addresses with Soft Bounces
  531. */
  532. function campaignSoftBounces($cid, $start=0, $limit=1000) {
  533. $params = array();
  534. $params["cid"] = $cid;
  535. $params["start"] = $start;
  536. $params["limit"] = $limit;
  537. return $this->callServer("campaignSoftBounces", $params);
  538. }
  539. /**
  540. * Get all unsubscribed email addresses for a given campaign
  541. *
  542. * @section Campaign Stats
  543. *
  544. * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
  545. * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
  546. * @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
  547. * @return array list of email addresses that unsubscribed from this campaign
  548. */
  549. function campaignUnsubscribes($cid, $start=0, $limit=1000) {
  550. $params = array();
  551. $params["cid"] = $cid;
  552. $params["start"] = $start;
  553. $params["limit"] = $limit;
  554. return $this->callServer("campaignUnsubscribes", $params);
  555. }
  556. /**
  557. * Get all email addresses that complained about a given campaign
  558. *
  559. * @section Campaign Stats
  560. *
  561. * @example mcapi_campaignAbuseReports.php
  562. *
  563. * @param string $cid the campaign id to pull abuse reports for (can be gathered using campaigns())
  564. * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
  565. * @param integer $limit optional for large data sets, the number of results to return - defaults to 500, upper limit set at 1000
  566. * @param string $since optional pull only messages since this time - use YYYY-MM-DD HH:II:SS format in <strong>GMT</strong>
  567. * @return array reports the abuse reports for this campaign
  568. * @returnf string date date/time the abuse report was received and processed
  569. * @returnf string email the email address that reported abuse
  570. * @returnf string type an internal type generally specifying the orginating mail provider - may not be useful outside of filling report views
  571. */
  572. function campaignAbuseReports($cid, $since=NULL, $start=0, $limit=500) {
  573. $params = array();
  574. $params["cid"] = $cid;
  575. $params["since"] = $since;
  576. $params["start"] = $start;
  577. $params["limit"] = $limit;
  578. return $this->callServer("campaignAbuseReports", $params);
  579. }
  580. /**
  581. * Retrieve the text presented in our app for how a campaign performed and any advice we may have for you - best
  582. * suited for display in customized reports pages. Note: some messages will contain HTML - clean tags as necessary
  583. *
  584. * @section Campaign Stats
  585. *
  586. * @example mcapi_campaignAdvice.php
  587. *
  588. * @param string $cid the campaign id to pull advice text for (can be gathered using campaigns())
  589. * @return array advice on the campaign's performance
  590. * @returnf msg the advice message
  591. * @returnf type the "type" of the message. one of: negative, positive, or neutral
  592. */
  593. function campaignAdvice($cid) {
  594. $params = array();
  595. $params["cid"] = $cid;
  596. return $this->callServer("campaignAdvice", $params);
  597. }
  598. /**
  599. * Retrieve the Google Analytics data we've collected for this campaign. Note, requires Google Analytics Add-on to be installed and configured.
  600. *
  601. * @section Campaign Stats
  602. *
  603. * @example mcapi_campaignAnalytics.php
  604. *
  605. * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
  606. * @return array analytics we've collected for the passed campaign.
  607. * @returnf integer visits number of visits
  608. * @returnf integer pages number of page views
  609. * @returnf integer new_visits new visits recorded
  610. * @returnf integer bounces vistors who "bounced" from your site
  611. * @returnf double time_on_site
  612. * @returnf integer goal_conversions number of goals converted
  613. * @returnf double goal_value value of conversion in dollars
  614. * @returnf double revenue revenue generated by campaign
  615. * @returnf integer transactions number of transactions tracked
  616. * @returnf integer ecomm_conversions number Ecommerce transactions tracked
  617. * @returnf array goals an array containing goal names and number of conversions
  618. */
  619. function campaignAnalytics($cid) {
  620. $params = array();
  621. $params["cid"] = $cid;
  622. return $this->callServer("campaignAnalytics", $params);
  623. }
  624. /**
  625. * Retrieve the countries and number of opens tracked for each. Email address are not returned.
  626. *
  627. * @section Campaign Stats
  628. *
  629. *
  630. * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
  631. * @return array countries an array of countries where opens occurred
  632. * @returnf string code The ISO3166 2 digit country code
  633. * @returnf string name A version of the country name, if we have it
  634. * @returnf int opens The total number of opens that occurred in the country
  635. * @returnf bool region_detail Whether or not a subsequent call to campaignGeoOpensByCountry() will return anything
  636. */
  637. function campaignGeoOpens($cid) {
  638. $params = array();
  639. $params["cid"] = $cid;
  640. return $this->callServer("campaignGeoOpens", $params);
  641. }
  642. /**
  643. * Retrieve the regions and number of opens tracked for a certain country. Email address are not returned.
  644. *
  645. * @section Campaign Stats
  646. *
  647. *
  648. * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
  649. * @param string $code An ISO3166 2 digit country code
  650. * @return array regions an array of regions within the provided country where opens occurred.
  651. * @returnf string code An internal code for the region. When this is blank, it indicates we know the country, but not the region
  652. * @returnf string name The name of the region, if we have one. For blank "code" values, this will be "Rest of Country"
  653. * @returnf int opens The total number of opens that occurred in the country
  654. */
  655. function campaignGeoOpensForCountry($cid, $code) {
  656. $params = array();
  657. $params["cid"] = $cid;
  658. $params["code"] = $code;
  659. return $this->callServer("campaignGeoOpensForCountry", $params);
  660. }
  661. /**
  662. * Retrieve the tracked eepurl mentions on Twitter
  663. *
  664. * @section Campaign Stats
  665. *
  666. *
  667. * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
  668. * @return array stats an array containing tweets and retweets including the campaign's eepurl
  669. * @returnf int tweets Total number of tweets seen
  670. * @returnf string first_tweet date and time of the first tweet seen
  671. * @returnf string last_tweet date and time of the last tweet seen
  672. * @returnf int retweets Total number of retweets seen
  673. * @returnf string first_retweet date and time of the first retweet seen
  674. * @returnf string last_retweet date and time of the last retweet seen
  675. * @returnf array statuses an array of statuses recorded inclduing the status, screen_name, status_id, and datetime fields plus an is_retweet flag
  676. */
  677. function campaignEepUrlStats($cid) {
  678. $params = array();
  679. $params["cid"] = $cid;
  680. return $this->callServer("campaignEepUrlStats", $params);
  681. }
  682. /**
  683. * Retrieve the full bounce messages for the given campaign. Note that this can return very large amounts
  684. * of data depending on how large the campaign was and how much cruft the bounce provider returned. Also,
  685. * message over 30 days old are subject to being removed
  686. *
  687. * @section Campaign Stats
  688. *
  689. * @example mcapi_campaignBounceMessages.php
  690. *
  691. * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
  692. * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
  693. * @param integer $limit optional for large data sets, the number of results to return - defaults to 25, upper limit set at 50
  694. * @param string $since optional pull only messages since this time - use YYYY-MM-DD format in <strong>GMT</strong> (we only store the date, not the time)
  695. * @return array bounces the full bounce messages for this campaign
  696. * @returnf string date date/time the bounce was received and processed
  697. * @returnf string email the email address that bounced
  698. * @returnf string message the entire bounce message received
  699. */
  700. function campaignBounceMessages($cid, $start=0, $limit=25, $since=NULL) {
  701. $params = array();
  702. $params["cid"] = $cid;
  703. $params["start"] = $start;
  704. $params["limit"] = $limit;
  705. $params["since"] = $since;
  706. return $this->callServer("campaignBounceMessages", $params);
  707. }
  708. /**
  709. * Retrieve the Ecommerce Orders tracked by campaignEcommAddOrder()
  710. *
  711. * @section Campaign Stats
  712. *
  713. * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
  714. * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
  715. * @param integer $limit optional for large data sets, the number of results to return - defaults to 100, upper limit set at 500
  716. * @param string $since optional pull only messages since this time - use YYYY-MM-DD HH:II:SS format in <strong>GMT</strong>
  717. * @return array orders the orders and their details that we've collected for this campaign
  718. * @returnf store_id string the store id generated by the plugin used to uniquely identify a store
  719. * @returnf store_name string the store name collected by the plugin - often the domain name
  720. * @returnf order_id string the internal order id the store tracked this order by
  721. * @returnf email string the email address that received this campaign and is associated with this order
  722. * @returnf order_total double the order total
  723. * @returnf tax_total double the total tax for the order (if collected)
  724. * @returnf ship_total double the shipping total for the order (if collected)
  725. * @returnf order_date string the date the order was tracked - from the store if possible, otherwise the GMT time we recieved it
  726. * @returnf lines array containing detail of the order - product, category, quantity, item cost
  727. */
  728. function campaignEcommOrders($cid, $start=0, $limit=100, $since=NULL) {
  729. $params = array();
  730. $params["cid"] = $cid;
  731. $params["start"] = $start;
  732. $params["limit"] = $limit;
  733. $params["since"] = $since;
  734. return $this->callServer("campaignEcommOrders", $params);
  735. }
  736. /**
  737. * Get the URL to a customized <a href="http://eepurl.com/gKmL" target="_blank">VIP Report</a> for the specified campaign and optionally send an email to someone with links to it. Note subsequent calls will overwrite anything already set for the same campign (eg, the password)
  738. *
  739. * @section Campaign Related
  740. *
  741. * @param string $cid the campaign id to share a report for (can be gathered using campaigns())
  742. * @param array $opts optional various parameters which can be used to configure the shared report
  743. string header_type optional - "text" or "image', defaults to "text'
  744. string header_data optional - if "header_type" is text, the text to display. if "header_type" is "image" a valid URL to an image file. Note that images will be resized to be no more than 500x150. Defaults to the Accounts Company Name.
  745. boolean secure optional - whether to require a password for the shared report. defaults to "true"
  746. string password optional - if secure is true and a password is not included, we will generate one. It is always returned.
  747. string to_email optional - optional, email address to share the report with - no value means an email will not be sent
  748. array theme optional - an array containing either 3 or 6 character color code values for: "bg_color", "header_color", "current_tab", "current_tab_text", "normal_tab", "normal_tab_text", "hover_tab", "hover_tab_text"
  749. string css_url optional - a link to an external CSS file to be included after our default CSS (http://vip-reports.net/css/vip.css) <strong>only if</strong> loaded via the "secure_url" - max 255 characters
  750. * @return struct Struct containing details for the shared report
  751. * @returnf string title The Title of the Campaign being shared
  752. * @returnf string url The URL to the shared report
  753. * @returnf string secure_url The URL to the shared report, including the password (good for loading in an IFRAME). For non-secure reports, this will not be returned
  754. * @returnf string password If secured, the password for the report, otherwise this field will not be returned
  755. */
  756. function campaignShareReport($cid, $opts=array (
  757. )) {
  758. $params = array();
  759. $params["cid"] = $cid;
  760. $params["opts"] = $opts;
  761. return $this->callServer("campaignShareReport", $params);
  762. }
  763. /**
  764. * Get the content (both html and text) for a campaign either as it would appear in the campaign archive or as the raw, original content
  765. *
  766. * @section Campaign Related
  767. *
  768. * @param string $cid the campaign id to get content for (can be gathered using campaigns())
  769. * @param bool $for_archive optional controls whether we return the Archive version (true) or the Raw version (false), defaults to true
  770. * @return struct Struct containing all content for the campaign (see Returned Fields for details
  771. * @returnf string html The HTML content used for the campgain with merge tags intact
  772. * @returnf string text The Text content used for the campgain with merge tags intact
  773. */
  774. function campaignContent($cid, $for_archive=true) {
  775. $params = array();
  776. $params["cid"] = $cid;
  777. $params["for_archive"] = $for_archive;
  778. return $this->callServer("campaignContent", $params);
  779. }
  780. /**
  781. * Retrieve the list of email addresses that opened a given campaign with how many times they opened - note: this AIM function is free and does
  782. * not actually require the AIM module to be installed
  783. *
  784. * @section Campaign AIM
  785. *
  786. * @param string $cid the campaign id to get opens for (can be gathered using campaigns())
  787. * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
  788. * @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
  789. * @return array Array of structs containing email addresses and open counts
  790. * @returnf string email Email address that opened the campaign
  791. * @returnf integer open_count Total number of times the campaign was opened by this email address
  792. */
  793. function campaignOpenedAIM($cid, $start=0, $limit=1000) {
  794. $params = array();
  795. $params["cid"] = $cid;
  796. $params["start"] = $start;
  797. $params["limit"] = $limit;
  798. return $this->callServer("campaignOpenedAIM", $params);
  799. }
  800. /**
  801. * Retrieve the list of email addresses that did not open a given campaign
  802. *
  803. * @section Campaign AIM
  804. *
  805. * @param string $cid the campaign id to get no opens for (can be gathered using campaigns())
  806. * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
  807. * @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
  808. * @return array list of email addresses that did not open a campaign
  809. */
  810. function campaignNotOpenedAIM($cid, $start=0, $limit=1000) {
  811. $params = array();
  812. $params["cid"] = $cid;
  813. $params["start"] = $start;
  814. $params["limit"] = $limit;
  815. return $this->callServer("campaignNotOpenedAIM", $params);
  816. }
  817. /**
  818. * Return the list of email addresses that clicked on a given url, and how many times they clicked
  819. *
  820. * @section Campaign AIM
  821. *
  822. * @param string $cid the campaign id to get click stats for (can be gathered using campaigns())
  823. * @param string $url the URL of the link that was clicked on
  824. * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
  825. * @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
  826. * @return array Array of structs containing email addresses and click counts
  827. * @returnf string email Email address that opened the campaign
  828. * @returnf integer clicks Total number of times the URL was clicked on by this email address
  829. */
  830. function campaignClickDetailAIM($cid, $url, $start=0, $limit=1000) {
  831. $params = array();
  832. $params["cid"] = $cid;
  833. $params["url"] = $url;
  834. $params["start"] = $start;
  835. $params["limit"] = $limit;
  836. return $this->callServer("campaignClickDetailAIM", $params);
  837. }
  838. /**
  839. * Given a campaign and email address, return the entire click and open history with timestamps, ordered by time
  840. *
  841. * @section Campaign AIM
  842. *
  843. * @param string $cid the campaign id to get stats for (can be gathered using campaigns())
  844. * @param string $email_address the email address to check OR the email "id" returned from listMemberInfo, Webhooks, and Campaigns
  845. * @return array Array of structs containing the actions (opens and clicks) that the email took, with timestamps
  846. * @returnf string action The action taken (open or click)
  847. * @returnf date timestamp Time the action occurred
  848. * @returnf string url For clicks, the URL that was clicked
  849. */
  850. function campaignEmailStatsAIM($cid, $email_address) {
  851. $params = array();
  852. $params["cid"] = $cid;
  853. $params["email_address"] = $email_address;
  854. return $this->callServer("campaignEmailStatsAIM", $params);
  855. }
  856. /**
  857. * Given a campaign and correct paging limits, return the entire click and open history with timestamps, ordered by time,
  858. * for every user a campaign was delivered to.
  859. *
  860. * @section Campaign AIM
  861. * @example mcapi_campaignEmailStatsAIMAll.php
  862. *
  863. * @param string $cid the campaign id to get stats for (can be gathered using campaigns())
  864. * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
  865. * @param integer $limit optional for large data sets, the number of results to return - defaults to 100, upper limit set at 1000
  866. * @return array Array of structs containing actions (opens and clicks) for each email, with timestamps
  867. * @returnf string action The action taken (open or click)
  868. * @returnf date timestamp Time the action occurred
  869. * @returnf string url For clicks, the URL that was clicked
  870. */
  871. function campaignEmailStatsAIMAll($cid, $start=0, $limit=100) {
  872. $params = array();
  873. $params["cid"] = $cid;
  874. $params["start"] = $start;
  875. $params["limit"] = $limit;
  876. return $this->callServer("campaignEmailStatsAIMAll", $params);
  877. }
  878. /**
  879. * Attach Ecommerce Order Information to a Campaign. This will generall be used by ecommerce package plugins
  880. * <a href="/plugins/ecomm360.phtml">that we provide</a> or by 3rd part system developers.
  881. * @section Campaign Related
  882. *
  883. * @param array $order an array of information pertaining to the order that has completed. Use the following keys:
  884. string id the Order Id
  885. string campaign_id the Campaign Id to track this order with (see the "mc_cid" query string variable a campaign passes)
  886. string email_id the Email Id of the subscriber we should attach this order to (see the "mc_eid" query string variable a campaign passes)
  887. double total The Order Total (ie, the full amount the customer ends up paying)
  888. string order_date optional the date of the order - if this is not provided, we will default the date to now
  889. double shipping optional the total paid for Shipping Fees
  890. double tax optional the total tax paid
  891. string store_id a unique id for the store sending the order in
  892. string store_name optional a "nice" name for the store - typically the base web address (ie, "store.mailchimp.com"). We will automatically update this if it changes (based on store_id)
  893. string plugin_id the MailChimp assigned Plugin Id. Get yours by <a href="/api/register.php">registering here</a>
  894. array items the individual line items for an order using these keys:
  895. <div style="padding-left:30px"><table><tr><td colspan=*>
  896. integer line_num optional the line number of the item on the order. We will generate these if they are not passed
  897. integer product_id the store's internal Id for the product. Lines that do no contain this will be skipped
  898. string product_name the product name for the product_id associated with this item. We will auto update these as they change (based on product_id)
  899. integer category_id the store's internal Id for the (main) category associated with this product. Our testing has found this to be a "best guess" scenario
  900. string category_name the category name for the category_id this product is in. Our testing has found this to be a "best guess" scenario. Our plugins walk the category heirarchy up and send "Root - SubCat1 - SubCat4", etc.
  901. double qty the quantity of the item ordered
  902. double cost the cost of a single item (ie, not the extended cost of the line)
  903. </td></tr></table></div>
  904. * @return bool true if the data is saved, otherwise an error is thrown.
  905. */
  906. function campaignEcommAddOrder($order) {
  907. $params = array();
  908. $params["order"] = $order;
  909. return $this->callServer("campaignEcommAddOrder", $params);
  910. }
  911. /**
  912. * Retrieve all of the lists defined for your user account
  913. *
  914. * @section List Related
  915. * @example mcapi_lists.php
  916. * @example xml-rpc_lists.php
  917. *
  918. * @return array list of your Lists and their associated information (see Returned Fields for description)
  919. * @returnf string id The list id for this list. This will be used for all other list management functions.
  920. * @returnf integer web_id The list id used in our web app, allows you to create a link directly to it
  921. * @returnf string name The name of the list.
  922. * @returnf date date_created The date that this list was created.
  923. * @returnf integer member_count The number of active members in the given list.
  924. * @returnf integer unsubscribe_count The number of members who have unsubscribed from the given list.
  925. * @returnf integer cleaned_count The number of members cleaned from the given list.
  926. * @returnf boolean email_type_option Whether or not the List supports multiple formats for emails or just HTML
  927. * @returnf string default_from_name Default From Name for campaigns using this list
  928. * @returnf string default_from_email Default From Email for campaigns using this list
  929. * @returnf string default_subject Default Subject Line for campaigns using this list
  930. * @returnf string default_language Default Language for this list's forms
  931. * @returnf double list_rating An auto-generated activity score for the list (0 - 5)
  932. * @returnf integer member_count The number of active members in the given list since the last campaign was sent
  933. * @returnf integer unsubscribe_count The number of members who have unsubscribed from the given list since the last campaign was sent
  934. * @returnf integer cleaned_count The number of members cleaned from the given list since the last campaign was sent
  935. */
  936. function lists() {
  937. $params = array();
  938. return $this->callServer("lists", $params);
  939. }
  940. /**
  941. * Get the list of merge tags for a given list, including their name, tag, and required setting
  942. *
  943. * @section List Related
  944. * @example xml-rpc_listMergeVars.php
  945. *
  946. * @param string $id the list id to connect to. Get by calling lists()
  947. * @return array list of merge tags for the list
  948. * @returnf string name Name of the merge field
  949. * @returnf char req Denotes whether the field is required (Y) or not (N)
  950. * @returnf string tag The merge tag that's used for forms and listSubscribe() and listUpdateMember()
  951. */
  952. function listMergeVars($id) {
  953. $params = array();
  954. $params["id"] = $id;
  955. return $this->callServer("listMergeVars", $params);
  956. }
  957. /**
  958. * Add a new merge tag to a given list
  959. *
  960. * @section List Related
  961. * @example xml-rpc_listMergeVarAdd.php
  962. *
  963. * @param string $id the list id to connect to. Get by calling lists()
  964. * @param string $tag The merge tag to add, e.g. FNAME
  965. * @param string $name The long description of the tag being added, used for user displays
  966. * @param array $req optional Various options for this merge var. <em>note:</em> for historical purposes this can also take a "boolean"
  967. string field_type optional one of: text, number, radio, dropdownn, date, address, phone, url, imageurl - defaults to text
  968. boolean req optional indicates whether the field is required - defaults to false
  969. boolean public optional indicates whether the field is displayed in public - defaults to true
  970. boolean show optional indicates whether the field is displayed in the app's list member view - defaults to true
  971. string default_value optional the default value for the field. See listSubscribe() for formatting info. Defaults to blank
  972. array choices optional kind of - an array of strings to use as the choices for radio and dropdown type fields
  973. * @return bool true if the request succeeds, otherwise an error will be thrown
  974. */
  975. function listMergeVarAdd($id, $tag, $name, $req=array (
  976. )) {
  977. $params = array();
  978. $params["id"] = $id;
  979. $params["tag"] = $tag;
  980. $params["name"] = $name;
  981. $params["req"] = $req;
  982. return $this->callServer("listMergeVarAdd", $params);
  983. }
  984. /**
  985. * Update most parameters for a merge tag on a given list. You cannot currently change the merge type
  986. *
  987. * @section List Related
  988. *
  989. * @param string $id the list id to connect to. Get by calling lists()
  990. * @param string $tag The merge tag to update
  991. * @param array $options The options to change for a merge var. See listMergeVarAdd() for valid options
  992. * @return bool true if the request succeeds, otherwise an error will be thrown
  993. */
  994. function listMergeVarUpdate($id, $tag, $options) {
  995. $params = array();
  996. $params["id"] = $id;
  997. $params["tag"] = $tag;
  998. $params["options"] = $options;
  999. return $this->callServer("listMergeVarUpdate", $params);
  1000. }
  1001. /**
  1002. * Delete a merge tag from a given list and all its members. Seriously - the data is removed from all members as well!
  1003. * Note that on large lists this method may seem a bit slower than calls you typically make.
  1004. *
  1005. * @section List Related
  1006. * @example xml-rpc_listMergeVarDel.php
  1007. *
  1008. * @param string $id the list id to connect to. Get by calling lists()
  1009. * @param string $tag The merge tag to delete
  1010. * @return bool true if the request succeeds, otherwise an error will be thrown
  1011. */
  1012. function listMergeVarDel($id, $tag) {
  1013. $params = array();
  1014. $params["id"] = $id;
  1015. $params["tag"] = $tag;
  1016. return $this->callServer("listMergeVarDel", $params);
  1017. }
  1018. /**
  1019. * Get the list of interest groups for a given list, including the label and form information
  1020. *
  1021. * @section List Related
  1022. * @example xml-rpc_listInterestGroups.php
  1023. *
  1024. * @param string $id the list id to connect to. Get by calling lists()
  1025. * @return struct list of interest groups for the list
  1026. * @returnf string name Name for the Interest groups
  1027. * @returnf string form_field Gives the type of interest group: checkbox,radio,select
  1028. * @returnf array groups Array of the group names
  1029. */
  1030. function listInterestGroups($id) {
  1031. $params = array();
  1032. $params["id"] = $id;
  1033. return $this->callServer("listInterestGroups", $params);
  1034. }
  1035. /** Add a single Interest Group - if interest groups for the List are not yet enabled, adding the first
  1036. * group will automatically turn them on.
  1037. *
  1038. * @section List Related
  1039. * @example xml-rpc_listInterestGroupAdd.php
  1040. *
  1041. * @param string $id the list id to connect to. Get by calling lists()
  1042. * @param string $group_name the interest group to add
  1043. * @return bool true if the request succeeds, otherwise an error will be thrown
  1044. */
  1045. function listInterestGroupAdd($id, $group_name) {
  1046. $params = array();
  1047. $params["id"] = $id;
  1048. $params["group_name"] = $group_name;
  1049. return $this->callServer("listInterestGroupAdd", $params);
  1050. }
  1051. /** Delete a single Interest Group - if the last group for a list is deleted, this will also turn groups for the list off.
  1052. *
  1053. * @section List Related
  1054. * @example xml-rpc_listInterestGroupDel.php
  1055. *
  1056. * @param string $id the list id to connect to. Get by calling lists()
  1057. * @param string $group_name the interest group to delete
  1058. * @return bool true if the request succeeds, otherwise an error will be thrown
  1059. */
  1060. function listInterestGroupDel($id, $group_name) {
  1061. $params = array();
  1062. $params["id"] = $id;
  1063. $params["group_name"] = $group_name;
  1064. return $this->callServer("listInterestGroupDel", $params);
  1065. }
  1066. /** Change the name of an Interest Group
  1067. *
  1068. * @section List Related
  1069. *
  1070. * @param string $id the list id to connect to. Get by calling lists()
  1071. * @param string $old_name the interest group name to be changed
  1072. * @param string $new_name the new interest group name to be set
  1073. * @return bool true if the request succeeds, otherwise an error will be thrown
  1074. */
  1075. function listInterestGroupUpdate($id, $old_name, $new_name) {
  1076. $params = array();
  1077. $params["id"] = $id;
  1078. $params["old_name"] = $old_name;
  1079. $params["new_name"] = $new_name;
  1080. return $this->callServer("listInterestGroupUpdate", $params);
  1081. }
  1082. /** Return the Webhooks configured for the given list
  1083. *
  1084. * @section List Related
  1085. *
  1086. * @param string $id the list id to connect to. Get by calling lists()
  1087. * @return array list of webhooks
  1088. * @returnf string url the URL for this Webhook
  1089. * @returnf array actions the possible actions and whether they are enabled
  1090. * @returnf array sources the possible sources and whether they are enabled
  1091. */
  1092. function listWebhooks($id) {
  1093. $params = array();
  1094. $params["id"] = $id;
  1095. return $this->callServer("listWebhooks", $params);
  1096. }
  1097. /** Add a new Webhook URL for the given list
  1098. *
  1099. * @section List Related
  1100. *
  1101. * @param string $id the list id to connect to. Get by calling lists()
  1102. * @param string $url a valid URL for the Webhook - it will be validated. note that a url may only exist on a list once.
  1103. * @param array $actions optional a hash of actions to fire this Webhook for
  1104. boolean subscribe optional as subscribes occur, defaults to true
  1105. boolean unsubscribe optional as subscribes occur, defaults to true
  1106. boolean profile optional as profile updates occur, defaults to true
  1107. boolean cleaned optional as emails are cleaned from the list, defaults to true
  1108. boolean upemail optional when subscribers change their email address, defaults to true
  1109. * @param array $sources optional a hash of sources to fire this Webhook for
  1110. boolean user optional user/subscriber initiated actions, defaults to true
  1111. boolean admin optional admin actions in our web app, defaults to true
  1112. boolean api optional actions that happen via API calls, defaults to false
  1113. * @return bool true if the call succeeds, otherwise an exception will be thrown
  1114. */
  1115. function listWebhookAdd($id, $url, $actions=array (
  1116. ), $sources=array (
  1117. )) {
  1118. $params = array();
  1119. $params["id"] = $id;
  1120. $params["url"] = $url;
  1121. $params["actions"] = $actions;
  1122. $params["sources"] = $sources;
  1123. return $this->callServer("listWebhookAdd", $params);
  1124. }
  1125. /** Delete an existing Webhook URL from a given list
  1126. *
  1127. * @section List Related
  1128. *
  1129. * @param string $id the list id to connect to. Get by calling lists()
  1130. * @param string $url the URL of a Webhook on this list
  1131. * @return boolean true if the call succeeds, otherwise an exception will be thrown
  1132. */
  1133. function listWebhookDel($id, $url) {
  1134. $params = array();
  1135. $params["id"] = $id;
  1136. $params["url"] = $url;
  1137. return $this->callServer("listWebhookDel", $params);
  1138. }
  1139. /**
  1140. * Subscribe the provided email to a list. By default this sends a confirmation email - you will not see new members until the link contained in it is clicked!
  1141. *
  1142. * @section List Related
  1143. *
  1144. * @example mcapi_listSubscribe.php
  1145. * @example xml-rpc_listSubscribe.php
  1146. *
  1147. * @param string $id the list id to connect to. Get by calling lists()
  1148. * @param string $email_address the email address to subscribe
  1149. * @param array $merge_vars array of merges for the email (FNAME, LNAME, etc.) (see examples below for handling "blank" arrays). Note that a merge field can only hold up to 255 characters. Also, there are a few "special" keys:
  1150. string EMAIL set this to change the email address. This is only respected on calls using update_existing or when passed to listUpdateMember()
  1151. string INTERESTS Set Interest Groups by passing a field named "INTERESTS" that contains a comma delimited list of Interest Groups to add. Commas in Interest Group names should be escaped with a backslash. ie, "," =&gt; "\,"
  1152. string OPTINIP Set the Opt-in IP fields. <em>Abusing this may cause your account to be suspended.</em> We do validate this and it must not be a private IP address.
  1153. <strong>Handling Field Data Types</strong> - most fields you can just pass a string and all is well. For some, though, that is not the case...
  1154. Field values should be formatted as follows:
  1155. string address For the string version of an Address, the fields should be delimited by <strong>2</strong> spaces. Address 2 can be skipped. The Country should be a 2 character ISO-3166-1 code and will default to your default country if not set
  1156. array address For the array version of an Address, the requirements for Address 2 and Country are the same as with the string version. Then simply pass us an array with the keys <strong>addr1</strong>, <strong>addr2</strong>, <strong>city</strong>, <strong>state</strong>, <strong>zip</strong>, <strong>country</strong> and appropriate values for each
  1157. string date use YYYY-MM-DD to be safe. Generally, though, anything strtotime() understands we'll understand - <a href="http://us2.php.net/strtotime" target="_blank">http://us2.php.net/strtotime</a>
  1158. string dropdown can be a normal string - we <em>will</em> validate that the value is a valid option
  1159. string image must be a valid, existing url. we <em>will</em> check its existence
  1160. string multi_choice can be a normal string - we <em>will</em> validate that the value is a valid option
  1161. double number pass in a valid number - anything else will turn in to zero (0). Note, this will be rounded to 2 decimal places
  1162. string phone If your account has the US Phone numbers option set, this <em>must</em> be in the form of NPA-NXX-LINE (404-555-1212). If not, we assume an International number and will simply set the field with what ever number is passed in.
  1163. string website This is a standard string, but we <em>will</em> verify that it looks like a valid URL
  1164. * @param string $email_type optional - email type preference for the email (html, text, or mobile defaults to html)
  1165. * @param boolean $double_optin optional - flag to control whether a double opt-in confirmation message is sent, defaults to true. <em>Abusing this may cause your account to be suspended.</em>
  1166. * @param boolean $update_existing optional - flag to control whether a existing subscribers should be updated instead of throwing and error
  1167. * @param boolean $replace_interests - flag to determine whether we replace the interest groups with the groups provided, or we add the provided groups to the member's interest groups (optional, defaults to true)
  1168. * @param boolean $send_welcome - if your double_optin is false and this is true, we will send your lists Welcome Email if this subscribe succeeds - this will *not* fire if we end up updating an existing subscriber. If double_optin is true, this has no effect. defaults to false.
  1169. * @return boolean true on success, false on failure. When using MCAPI.class.php, the value can be tested and error messages pulled from the MCAPI object (see below)
  1170. */
  1171. function listSubscribe($id, $email_address, $merge_vars, $email_type='html', $double_optin=true, $update_existing=false, $replace_interests=true, $send_welcome=false) {
  1172. $params = array();
  1173. $params["id"] = $id;
  1174. $params["email_address"] = $email_address;
  1175. $params["merge_vars"] = $merge_vars;
  1176. $params["email_type"] = $email_type;
  1177. $params["double_optin"] = $double_optin;
  1178. $params["update_existing"] = $update_existing;
  1179. $params["replace_interests"] = $replace_interests;
  1180. $params["send_welcome"] = $send_welcome;
  1181. return $this->callServer("listSubscribe", $params);
  1182. }
  1183. /**
  1184. * Unsubscribe the given email address from the list
  1185. *
  1186. * @section List Related
  1187. * @example mcapi_listUnsubscribe.php
  1188. * @example xml-rpc_listUnsubscribe.php
  1189. *
  1190. * @param string $id the list id to connect to. Get by calling lists()
  1191. * @param string $email_address the email address to unsubscribe OR the email "id" returned from listMemberInfo, Webhooks, and Campaigns
  1192. * @param boolean $delete_member flag to completely delete the member from your list instead of just unsubscribing, default to false
  1193. * @param boolean $send_goodbye flag to send the goodbye email to the email address, defaults to true
  1194. * @param boolean $send_notify flag to send the unsubscribe notification email to the address defined in the list email notification settings, defaults to true
  1195. * @return boolean true on success, false on failure. When using MCAPI.class.php, the value can be tested and error messages pulled from the MCAPI object (see below)
  1196. */
  1197. function listUnsubscribe($id, $email_address, $delete_member=false, $send_goodbye=true, $send_notify=true) {
  1198. $params = array();
  1199. $params["id"] = $id;
  1200. $params["email_address"] = $email_address;
  1201. $params["delete_member"] = $delete_member;
  1202. $params["send_goodbye"] = $send_goodbye;
  1203. $params["send_notify"] = $send_notify;
  1204. return $this->callServer("listUnsubscribe", $params);
  1205. }
  1206. /**
  1207. * Edit the email address, merge fields, and interest groups for a list member
  1208. *
  1209. * @section List Related
  1210. * @example mcapi_listUpdateMember.php
  1211. *
  1212. * @param string $id the list id to connect to. Get by calling lists()
  1213. * @param string $email_address the current email address of the member to update OR the "id" for the member returned from listMemberInfo, Webhooks, and Campaigns
  1214. * @param array $merge_vars array of new field values to update the member with. See merge_vars in listSubscribe() for details.
  1215. * @param string $email_type change the email type preference for the member ("html", "text", or "mobile"). Leave blank to keep the existing preference (optional)
  1216. * @param boolean $replace_interests flag to determine whether we replace the interest groups with the updated groups provided, or we add the provided groups to the member's interest groups (optional, defaults to true)
  1217. * @return boolean true on success, false on failure. When using MCAPI.class.php, the value can be tested and error messages pulled from the MCAPI object
  1218. */
  1219. function listUpdateMember($id, $email_address, $merge_vars, $email_type='', $replace_interests=true) {
  1220. $params = array();
  1221. $params["id"] = $id;
  1222. $params["email_address"] = $email_address;
  1223. $params["merge_vars"] = $merge_vars;
  1224. $params["email_type"] = $email_type;
  1225. $params["replace_interests"] = $replace_interests;
  1226. return $this->callServer("listUpdateMember", $params);
  1227. }
  1228. /**
  1229. * Subscribe a batch of email addresses to a list at once. If you are using a serialized version of the API, we strongly suggest that you
  1230. * only run this method as a POST request, and <em>not</em> a GET request.
  1231. *
  1232. * @section List Related
  1233. *
  1234. * @example mcapi_listBatchSubscribe.php
  1235. * @example xml-rpc_listBatchSubscribe.php
  1236. *
  1237. * @param string $id the list id to connect to. Get by calling lists()
  1238. * @param array $batch an array of structs for each address to import with two special keys: "EMAIL" for the email address, and "EMAIL_TYPE" for the email type option (html, text, or mobile)
  1239. * @param boolean $double_optin flag to control whether to send an opt-in confirmation email - defaults to true
  1240. * @param boolean $update_existing flag to control whether to update members that are already subscribed to the list or to return an error, defaults to false (return error)
  1241. * @param boolean $replace_interests flag to determine whether we replace the interest groups with the updated groups provided, or we add the provided groups to the member's interest groups (optional, defaults to true)
  1242. * @return struct Array of result counts and any errors that occurred
  1243. * @returnf integer success_count Number of email addresses that were succesfully added/updated
  1244. * @returnf integer error_count Number of email addresses that failed during addition/updating
  1245. * @returnf array errors Array of error structs. Each error struct will contain "code", "message", and the full struct that failed
  1246. */
  1247. function listBatchSubscribe($id, $batch, $double_optin=true, $update_existing=false, $replace_interests=true) {
  1248. $params = array();
  1249. $params["id"] = $id;
  1250. $params["batch"] = $batch;
  1251. $params["double_optin"] = $double_optin;
  1252. $params["update_existing"] = $update_existing;
  1253. $params["replace_interests"] = $replace_interests;
  1254. return $this->callServer("listBatchSubscribe", $params);
  1255. }
  1256. /**
  1257. * Unsubscribe a batch of email addresses to a list
  1258. *
  1259. * @section List Related
  1260. * @example mcapi_listBatchUnsubscribe.php
  1261. *
  1262. * @param string $id the list id to connect to. Get by calling lists()
  1263. * @param array $emails array of email addresses to unsubscribe
  1264. * @param boolean $delete_member flag to completely delete the member from your list instead of just unsubscribing, default to false
  1265. * @param boolean $send_goodbye flag to send the goodbye email to the email addresses, defaults to true
  1266. * @param boolean $send_notify flag to send the unsubscribe notification email to the address defined in the list email notification settings, defaults to false
  1267. * @return struct Array of result counts and any errors that occurred
  1268. * @returnf integer success_count Number of email addresses that were succesfully added/updated
  1269. * @returnf integer error_count Number of email addresses that failed during addition/updating
  1270. * @returnf array errors Array of error structs. Each error struct will contain "code", "message", and "email"
  1271. */
  1272. function listBatchUnsubscribe($id, $emails, $delete_member=false, $send_goodbye=true, $send_notify=false) {
  1273. $params = array();
  1274. $params["id"] = $id;
  1275. $params["emails"] = $emails;
  1276. $params["delete_member"] = $delete_member;
  1277. $params["send_goodbye"] = $send_goodbye;
  1278. $params["send_notify"] = $send_notify;
  1279. return $this->callServer("listBatchUnsubscribe", $params);
  1280. }
  1281. /**
  1282. * Get all of the list members for a list that are of a particular status
  1283. *
  1284. * @section List Related
  1285. * @example mcapi_listMembers.php
  1286. *
  1287. * @param string $id the list id to connect to. Get by calling lists()
  1288. * @param string $status the status to get members for - one of(subscribed, unsubscribed, cleaned, updated), defaults to subscribed
  1289. * @param string $since optional pull all members whose status (subscribed/unsubscribed/cleaned) has changed or whose profile (updated) has changed since this date/time (in GMT) - format is YYYY-MM-DD HH:mm:ss (24hr)
  1290. * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
  1291. * @param integer $limit optional for large data sets, the number of results to return - defaults to 100, upper limit set at 15000
  1292. * @return array Array of list member structs (see Returned Fields for details)
  1293. * @returnf string email Member email address
  1294. * @returnf date timestamp timestamp of their associated status date (subscribed, unsubscribed, cleaned, or updated) in GMT
  1295. */
  1296. function listMembers($id, $status='subscribed', $since=NULL, $start=0, $limit=100) {
  1297. $params = array();
  1298. $params["id"] = $id;
  1299. $params["status"] = $status;
  1300. $params["since"] = $since;
  1301. $params["start"] = $start;
  1302. $params["limit"] = $limit;
  1303. return $this->callServer("listMembers", $params);
  1304. }
  1305. /**
  1306. * Get all the information for a particular member of a list
  1307. *
  1308. * @section List Related
  1309. * @example mcapi_listMemberInfo.php
  1310. * @example xml-rpc_listMemberInfo.php
  1311. *
  1312. * @param string $id the list id to connect to. Get by calling lists()
  1313. * @param string $email_address the member email address to get information for OR the "id" for the member returned from listMemberInfo, Webhooks, and Campaigns
  1314. * @return array array of list member info (see Returned Fields for details)
  1315. * @returnf string id The unique id for this email address on an account
  1316. * @returnf string email The email address associated with this record
  1317. * @returnf string email_type The type of emails this customer asked to get: html, text, or mobile
  1318. * @returnf array merges An associative array of all the merge tags and the data for those tags for this email address. <em>Note</em>: Interest Groups are returned as comma delimited strings - if a group name contains a comma, it will be escaped with a backslash. ie, "," =&gt; "\,"
  1319. * @returnf string status The subscription status for this email address, either subscribed, unsubscribed or cleaned
  1320. * @returnf string ip_opt IP Address this address opted in from.
  1321. * @returnf string ip_signup IP Address this address signed up from.
  1322. * @returnf int member_rating the rating of the subscriber. This will be 1 - 5 as described <a href="http://eepurl.com/f-2P" target="_blank">here</a>
  1323. * @returnf string campaign_id If the user is unsubscribed and they unsubscribed from a specific campaign, that campaign_id will be listed, otherwise this is not returned.
  1324. * @returnf array lists An associative array of the other lists this member belongs to - the key is the list id and the value is their status in that list.
  1325. * @returnf date timestamp The time this email address was added to the list
  1326. */
  1327. function listMemberInfo($id, $email_address) {
  1328. $params = array();
  1329. $params["id"] = $id;
  1330. $params["email_address"] = $email_address;
  1331. return $this->callServer("listMemberInfo", $params);
  1332. }
  1333. /**
  1334. * Get all email addresses that complained about a given campaign
  1335. *
  1336. * @section List Related
  1337. *
  1338. * @example mcapi_listAbuseReports.php
  1339. *
  1340. * @param string $id the list id to pull abuse reports for (can be gathered using lists())
  1341. * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
  1342. * @param integer $limit optional for large data sets, the number of results to return - defaults to 500, upper limit set at 1000
  1343. * @param string $since optional pull only messages since this time - use YYYY-MM-DD HH:II:SS format in <strong>GMT</strong>
  1344. * @return array reports the abuse reports for this campaign
  1345. * @returnf string date date/time the abuse report was received and processed
  1346. * @returnf string email the email address that reported abuse
  1347. * @returnf string campaign_id the unique id for the campaign that reporte was made against
  1348. * @returnf string type an internal type generally specifying the orginating mail provider - may not be useful outside of filling report views
  1349. */
  1350. function listAbuseReports($id, $start=0, $limit=500, $since=NULL) {
  1351. $params = array();
  1352. $params["id"] = $id;
  1353. $params["start"] = $start;
  1354. $params["limit"] = $limit;
  1355. $params["since"] = $since;
  1356. return $this->callServer("listAbuseReports", $params);
  1357. }
  1358. /**
  1359. * Access the Growth History by Month for a given list.
  1360. *
  1361. * @section List Related
  1362. *
  1363. * @example mcapi_listGrowthHistory.php
  1364. *
  1365. * @param string $id the list id to connect to. Get by calling lists()
  1366. * @return array array of months and growth
  1367. * @returnf string month The Year and Month in question using YYYY-MM format
  1368. * @returnf integer existing number of existing subscribers to start the month
  1369. * @returnf integer imports number of subscribers imported during the month
  1370. * @returnf integer optins number of subscribers who opted-in during the month
  1371. */
  1372. function listGrowthHistory($id) {
  1373. $params = array();
  1374. $params["id"] = $id;
  1375. return $this->callServer("listGrowthHistory", $params);
  1376. }
  1377. /**
  1378. * <strong>DEPRECATED:</strong> Retrieve your User Unique Id and your Affiliate link to display/use for
  1379. * <a href="/monkeyrewards/" target="_blank">Monkey Rewards</a>. While
  1380. * we don't use the User Id for any API functions, it can be useful if building up URL strings for things such as the profile editor and sub/unsub links.
  1381. *
  1382. * @section Helper
  1383. *
  1384. * @deprecated See getAccountDetails() for replacement
  1385. *
  1386. * @example mcapi_getAffiliateInfo.php
  1387. * @example xml-rpc_getAffiliateInfo.php
  1388. *
  1389. * @return array containing your Affilliate Id and full link.
  1390. * @returnf string user_id Your User Unique Id.
  1391. * @returnf string url Your Monkey Rewards link for our Affiliate program
  1392. */
  1393. function getAffiliateInfo() {
  1394. $params = array();
  1395. return $this->callServer("getAffiliateInfo", $params);
  1396. }
  1397. /**
  1398. * Retrieve lots of account information including payments made, plan info, some account stats, installed modules,
  1399. * contact info, and more. No private information like Credit Card numbers is available.
  1400. *
  1401. * @section Helper
  1402. *
  1403. * @return array containing the details for the account tied to this API Key
  1404. * @returnf string username The Account username
  1405. * @returnf string user_id The Account user unique id (for building some links)
  1406. * @returnf bool is_trial Whether the Account is in Trial mode (can only send campaigns to less than 100 emails)
  1407. * @returnf string timezone The timezone for the Account - default is "US/Eastern"
  1408. * @returnf string plan_type Plan Type - "monthly", "payasyougo", or "free"
  1409. * @returnf int plan_low <em>only for Monthly plans</em> - the lower tier for list size
  1410. * @returnf int plan_high <em>only for Monthly plans</em> - the upper tier for list size
  1411. * @returnf datetime plan_start_date <em>only for Monthly plans</em> - the start date for a monthly plan
  1412. * @returnf int emails_left <em>only for Free and Pay-as-you-go plans</em> emails credits left for the account
  1413. * @returnf bool pending_monthly Whether the account is finishing Pay As You Go credits before switching to a Monthly plan
  1414. * @returnf datetime first_payment date of first payment
  1415. * @returnf datetime last_payment date of most recent payment
  1416. * @returnf int times_logged_in total number of times the account has been logged into via the web
  1417. * @returnf datetime last_login date/time of last login via the web
  1418. * @returnf string affiliate_link Monkey Rewards link for our Affiliate program
  1419. * @returnf array contact Contact details for the account, including: First & Last name, email, company name, address, phone, and url
  1420. * @returnf array addons Addons installed in the account and the date they were installed.
  1421. * @returnf array orders Order details for the account, include order_id, type, cost, date/time, and any credits applied to the order
  1422. * @returnf array rewards Rewards details for the account including credits & inspections earned, number of referals, referal details, and rewards used
  1423. */
  1424. function getAccountDetails() {
  1425. $params = array();
  1426. return $this->callServer("getAccountDetails", $params);
  1427. }
  1428. /**
  1429. * Have HTML content auto-converted to a text-only format. You can send: plain HTML, an array of Template content, an existing Campaign Id, or an existing Template Id. Note that this will <b>not</b> save anything to or update any of your lists, campaigns, or templates.
  1430. *
  1431. * @section Helper
  1432. * @example xml-rpc_generateText.php
  1433. *
  1434. * @param string $type The type of content to parse. Must be one of: "html", "template", "url", "cid" (Campaign Id), or "tid" (Template Id)
  1435. * @param mixed $content The content to use. For "html" expects a single string value, "template" expects an array like you send to campaignCreate, "url" expects a valid & public URL to pull from, "cid" expects a valid Campaign Id, and "tid" expects a valid Template Id on your account.
  1436. * @return string the content pass in converted to text.
  1437. */
  1438. function generateText($type, $content) {
  1439. $params = array();
  1440. $params["type"] = $type;
  1441. $params["content"] = $content;
  1442. return $this->callServer("generateText", $params);
  1443. }
  1444. /**
  1445. * Send your HTML content to have the CSS inlined and optionally remove the original styles.
  1446. *
  1447. * @section Helper
  1448. * @example xml-rpc_inlineCss.php
  1449. *
  1450. * @param string $html Your HTML content
  1451. * @param bool $strip_css optional Whether you want the CSS &lt;style&gt; tags stripped from the returned document. Defaults to false.
  1452. * @return string Your HTML content with all CSS inlined, just like if we sent it.
  1453. */
  1454. function inlineCss($html, $strip_css=false) {
  1455. $params = array();
  1456. $params["html"] = $html;
  1457. $params["strip_css"] = $strip_css;
  1458. return $this->callServer("inlineCss", $params);
  1459. }
  1460. /**
  1461. * Create a new folder to file campaigns in
  1462. *
  1463. * @section Helper
  1464. * @example mcapi_createFolder.php
  1465. * @example xml-rpc_createFolder.php
  1466. *
  1467. * @param string $name a unique name for a folder
  1468. * @return integer the folder_id of the newly created folder.
  1469. */
  1470. function createFolder($name) {
  1471. $params = array();
  1472. $params["name"] = $name;
  1473. return $this->callServer("createFolder", $params);
  1474. }
  1475. /**
  1476. * Import Ecommerce Order Information to be used for Segmentatio. This will generall be used by ecommerce package plugins
  1477. * <a href="/plugins/ecomm360.phtml">that we provide</a> or by 3rd part system developers.
  1478. * @section Helper
  1479. *
  1480. * @param array $order an array of information pertaining to the order that has completed. Use the following keys:
  1481. string id the Order Id
  1482. string email_id optional (kind of) the Email Id of the subscriber we should attach this order to (see the "mc_eid" query string variable a campaign passes) - either this or <strong>email</strong> is required. If both are provided, email_id takes precedence
  1483. string email optional (kind of) the Email Address we should attach this order to - either this or <strong>email_id</strong> is required. If both are provided, email_id takes precedence
  1484. double total The Order Total (ie, the full amount the customer ends up paying)
  1485. string order_date optional the date of the order - if this is not provided, we will default the date to now
  1486. double shipping optional the total paid for Shipping Fees
  1487. double tax optional the total tax paid
  1488. string store_id a unique id for the store sending the order in
  1489. string store_name optional a "nice" name for the store - typically the base web address (ie, "store.mailchimp.com"). We will automatically update this if it changes (based on store_id)
  1490. string plugin_id the MailChimp assigned Plugin Id. Get yours by <a href="/api/register.php">registering here</a>
  1491. string campaign_id optional the Campaign Id to track this order with (see the "mc_cid" query string variable a campaign passes)
  1492. array items the individual line items for an order using these keys:
  1493. <div style="padding-left:30px"><table><tr><td colspan=*>
  1494. integer line_num optional the line number of the item on the order. We will generate these if they are not passed
  1495. integer product_id the store's internal Id for the product. Lines that do no contain this will be skipped
  1496. string product_name the product name for the product_id associated with this item. We will auto update these as they change (based on product_id)
  1497. integer category_id the store's internal Id for the (main) category associated with this product. Our testing has found this to be a "best guess" scenario
  1498. string category_name the category name for the category_id this product is in. Our testing has found this to be a "best guess" scenario. Our plugins walk the category heirarchy up and send "Root - SubCat1 - SubCat4", etc.
  1499. double qty the quantity of the item ordered
  1500. double cost the cost of a single item (ie, not the extended cost of the line)
  1501. </td></tr></table></div>
  1502. * @return bool true if the data is saved, otherwise an error is thrown.
  1503. */
  1504. function ecommAddOrder($order) {
  1505. $params = array();
  1506. $params["order"] = $order;
  1507. return $this->callServer("ecommAddOrder", $params);
  1508. }
  1509. /**
  1510. * Retrieve all List Ids a member is subscribed to.
  1511. *
  1512. * @section Helper
  1513. *
  1514. * @param string $email_address the email address to unsubscribe OR the email "id" returned from listMemberInfo, Webhooks, and Campaigns
  1515. * @return array An array of list_ids the member is subscribed to.
  1516. */
  1517. function listsForEmail($email_address) {
  1518. $params = array();
  1519. $params["email_address"] = $email_address;
  1520. return $this->callServer("listsForEmail", $params);
  1521. }
  1522. /**
  1523. * Return the current Chimp Chatter messages for an account.
  1524. *
  1525. * @section Helper
  1526. *
  1527. * @return array An array of chatter messages and properties
  1528. * @returnf string message The chatter message
  1529. * @returnf string type The type of the message - one of scheduled, sent, inspection, subscribes, unsubscribes, low_credits, absplit, best_opens, best_clicks, or abuse
  1530. * @returnf string list_id the list_id a message relates to, if applicable
  1531. * @returnf string campaign_id the list_id a message relates to, if applicable
  1532. * @returnf string update_time The date/time the message was last updated
  1533. */
  1534. function chimpChatter() {
  1535. $params = array();
  1536. return $this->callServer("chimpChatter", $params);
  1537. }
  1538. /**
  1539. * Retrieve a list of all MailChimp API Keys for this User
  1540. *
  1541. * @section Security Related
  1542. * @example xml-rpc_apikeyAdd.php
  1543. * @example mcapi_apikeyAdd.php
  1544. *
  1545. * @param string $username Your MailChimp user name
  1546. * @param string $password Your MailChimp password
  1547. * @param boolean $expired optional - whether or not to include expired keys, defaults to false
  1548. * @return array an array of API keys including:
  1549. * @returnf string apikey The api key that can be used
  1550. * @returnf string created_at The date the key was created
  1551. * @returnf string expired_at The date the key was expired
  1552. */
  1553. function apikeys($username, $password, $expired=false) {
  1554. $params = array();
  1555. $params["username"] = $username;
  1556. $params["password"] = $password;
  1557. $params["expired"] = $expired;
  1558. return $this->callServer("apikeys", $params);
  1559. }
  1560. /**
  1561. * Add an API Key to your account. We will generate a new key for you and return it.
  1562. *
  1563. * @section Security Related
  1564. * @example xml-rpc_apikeyAdd.php
  1565. *
  1566. * @param string $username Your MailChimp user name
  1567. * @param string $password Your MailChimp password
  1568. * @return string a new API Key that can be immediately used.
  1569. */
  1570. function apikeyAdd($username, $password) {
  1571. $params = array();
  1572. $params["username"] = $username;
  1573. $params["password"] = $password;
  1574. return $this->callServer("apikeyAdd", $params);
  1575. }
  1576. /**
  1577. * Expire a Specific API Key. Note that if you expire all of your keys, just visit <a href="http://admin.mailchimp.com/account/api" target="_blank">your API dashboard</a>
  1578. * to create a new one. If you are trying to shut off access to your account for an old developer, change your
  1579. * MailChimp password, then expire all of the keys they had access to. Note that this takes effect immediately, so make
  1580. * sure you replace the keys in any working application before expiring them! Consider yourself warned...
  1581. *
  1582. * @section Security Related
  1583. * @example mcapi_apikeyExpire.php
  1584. * @example xml-rpc_apikeyExpire.php
  1585. *
  1586. * @param string $username Your MailChimp user name
  1587. * @param string $password Your MailChimp password
  1588. * @return boolean true if it worked, otherwise an error is thrown.
  1589. */
  1590. function apikeyExpire($username, $password) {
  1591. $params = array();
  1592. $params["username"] = $username;
  1593. $params["password"] = $password;
  1594. return $this->callServer("apikeyExpire", $params);
  1595. }
  1596. /**
  1597. * "Ping" the MailChimp API - a simple method you can call that will return a constant value as long as everything is good. Note
  1598. * than unlike most all of our methods, we don't throw an Exception if we are having issues. You will simply receive a different
  1599. * string back that will explain our view on what is going on.
  1600. *
  1601. * @section Helper
  1602. * @example xml-rpc_ping.php
  1603. *
  1604. * @return string returns "Everything's Chimpy!" if everything is chimpy, otherwise returns an error message
  1605. */
  1606. function ping() {
  1607. $params = array();
  1608. return $this->callServer("ping", $params);
  1609. }
  1610. /**
  1611. * Internal function - proxy method for certain XML-RPC calls | DO NOT CALL
  1612. * @param mixed Method to call, with any parameters to pass along
  1613. * @return mixed the result of the call
  1614. */
  1615. function callMethod() {
  1616. $params = array();
  1617. return $this->callServer("callMethod", $params);
  1618. }
  1619. /**
  1620. * Actually connect to the server and call the requested methods, parsing the result
  1621. * You should never have to call this function manually
  1622. */
  1623. function callServer($method, $params) {
  1624. $dc = "us1";
  1625. if (strstr($this->api_key,"-")){
  1626. list($key, $dc) = explode("-",$this->api_key,2);
  1627. if (!$dc) $dc = "us1";
  1628. }
  1629. $host = $dc.".".$this->apiUrl["host"];
  1630. $params["apikey"] = $this->api_key;
  1631. $this->errorMessage = "";
  1632. $this->errorCode = "";
  1633. $post_vars = $this->httpBuildQuery($params);
  1634. $payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
  1635. $payload .= "Host: " . $host . "\r\n";
  1636. $payload .= "User-Agent: MCAPI/" . $this->version ."\r\n";
  1637. $payload .= "Content-type: application/x-www-form-urlencoded\r\n";
  1638. $payload .= "Content-length: " . strlen($post_vars) . "\r\n";
  1639. $payload .= "Connection: close \r\n\r\n";
  1640. $payload .= $post_vars;
  1641. ob_start();
  1642. if ($this->secure){
  1643. $sock = fsockopen("ssl://".$host, 443, $errno, $errstr, 30);
  1644. } else {
  1645. $sock = fsockopen($host, 80, $errno, $errstr, 30);
  1646. }
  1647. if(!$sock) {
  1648. $this->errorMessage = "Could not connect (ERR $errno: $errstr)";
  1649. $this->errorCode = "-99";
  1650. ob_end_clean();
  1651. return false;
  1652. }
  1653. $response = "";
  1654. fwrite($sock, $payload);
  1655. stream_set_timeout($sock, $this->timeout);
  1656. $info = stream_get_meta_data($sock);
  1657. while ((!feof($sock)) && (!$info["timed_out"])) {
  1658. $response .= fread($sock, $this->chunkSize);
  1659. $info = stream_get_meta_data($sock);
  1660. }
  1661. if ($info["timed_out"]) {
  1662. $this->errorMessage = "Could not read response (timed out)";
  1663. $this->errorCode = -98;
  1664. }
  1665. fclose($sock);
  1666. ob_end_clean();
  1667. if ($info["timed_out"]) return false;
  1668. list($throw, $response) = explode("\r\n\r\n", $response, 2);
  1669. if(ini_get("magic_quotes_runtime")) $response = stripslashes($response);
  1670. $serial = unserialize($response);
  1671. if($response && $serial === false) {
  1672. $response = array("error" => "Bad Response. Got This: " . $response, "code" => "-99");
  1673. } else {
  1674. $response = $serial;
  1675. }
  1676. if(is_array($response) && isset($response["error"])) {
  1677. $this->errorMessage = $response["error"];
  1678. $this->errorCode = $response["code"];
  1679. return false;
  1680. }
  1681. return $response;
  1682. }
  1683. /**
  1684. * Re-implement http_build_query for systems that do not already have it
  1685. */
  1686. function httpBuildQuery($params, $key=null) {
  1687. $ret = array();
  1688. foreach((array) $params as $name => $val) {
  1689. $name = urlencode($name);
  1690. if($key !== null) {
  1691. $name = $key . "[" . $name . "]";
  1692. }
  1693. if(is_array($val) || is_object($val)) {
  1694. $ret[] = $this->httpBuildQuery($val, $name);
  1695. } elseif($val !== null) {
  1696. $ret[] = $name . "=" . urlencode($val);
  1697. }
  1698. }
  1699. return implode("&", $ret);
  1700. }
  1701. }
  1702. ?>