PHP MailChimp Campaign CSV Parser

The MailChimp Campaign CSV Parser is a PHP library to take a downloaded MailChimp Campaign CSV export and parse it in a easy-to-use array. Includes industry rates to compare statistics with.

I’ve worked with MailChimp a lot in past and current projects. My biggest compliant is they’re lack of detailed reports and overly restrictive API usage limits. A common problem I’ve had is extrapolating data from they’re campaign CSV reports — I do this because you can pull more data from the downloaded CSV at one time than the API. A long list of campaign details is useless to marketers if they can’t easy consume, comprehend and make quick decisions off the data. That’s where the MailChimp Campaign CSV Parser PHP library comes in.

Continue reading “PHP MailChimp Campaign CSV Parser”

MailChimp PHP API Class: Simple Library for MailChimp API V2

The past couple of months I’ve been working to move a little over 260,000 subscribers from Eloqua to MailChimp. The company that owns the site does heavy email marketing that differs from the typical MailChimp user. This requires some advanced functionality that MailChimp’s interface does not provide. The solution, MailChimp API which allows us to build out our own custom functionality where MailChimp falls short.

The past couple of months I’ve been working to move a little over 260,000 subscribers from Eloqua to MailChimp. The company that owns the site does heavy email marketing that differs from the typical MailChimp user. This requires some advanced functionality that MailChimp’s interface does not provide. The solution, MailChimp API which allows us to build out our own custom functionality where MailChimp falls short.

I was going to build out my own MailChimp PHP API class, but luckily after a little digging, found Drew McLellan‘s MailChimp v2 wrapper. Unlike a lot of the PHP libraries out that are complex, confusing wrappers, this one is super-simple and light-weight. It allows you to quickly access the MailChimp API and start coding your own applications.

Download the MailChimp PHP API Class

MailChimp PHP API Class

Using this MailChimp PHP API Class is as simple as the class is itself. You can either download it by clicking the button above or install the mailchimp-api using Composer. In order to install it with Composer, see the docs for more details.

Once you’ve got it installed, you’ll be ready to build out your application. Just grab your MailChimp API key and initialize the class.

Once initialized, you can begin calling out to the MailChimp API and request the data or functionality you need for your app.

MailChimp PHP API Class Examples

I’m a visual learner, so put together some examples for the MailChimp PHP API Class. I’m also interested in how others use APIs to build out applications. Be sure to comment below and let me know how you’ve integrated this API for your projects.

List Related Methods

List Related Methods

These are just a few examples using the MailChimp API. Check out their docs for a full list and details of all the methods they provide.


MailChimp List Related Methods

Get emails that complained.

MailChimp API Method:
lists/abuse-reports (string apikey, string id, int start, int limit, string since)

Access up to 180 days of aggregated activity for a list (does not include AutoResponder activity).

MailChimp API Method:
lists/activity (string apikey, string id)

Subscribe a batch of emails.

MailChimp API Method:
lists/batch-subscribe (string apikey, string id, array batch, boolean double_optin, boolean update_existing, boolean replace_interests)

Maximum batch sizes vary based on the amount of data in each record, though you should cap them at 5k – 10k records, depending on your experience. These calls are also long, so be sure you increase your timeout values.

Unsubscribe a batch of emails.

MailChimp API Method:
lists/batch-unsubscribe (string apikey, string id, array batch, boolean delete_member, boolean send_goodbye, boolean send_notify)

Retrieve the clients that the list’s subscribers have been tagged as being used.

MailChimp API Method:
lists/clients (string apikey, string id)

Access the Growth History by Month in aggregate or for a given list.

MailChimp API Method:
lists/growth-history (string apikey, string id)

Add a single Interest Group.

MailChimp API Method:
lists/interest-group-add (string apikey, string id, string group_name, int grouping_id)

If interest groups for the List are not yet enabled, adding the first group will automatically turn them on.

Delete a single Interest Group.

MailChimp API Method:
lists/interest-group-del (string apikey, string id, string group_name, int grouping_id)

If the last group for a list is deleted, this will also turn groups for the list off.

Change the name of an Interest Group.

MailChimp API Method:
lists/interest-group-del (string apikey, string id, string old_name, string new_name, int grouping_id)

Get the list of interest groupings for a given list.

MailChimp API Method:
lists/interest-groupings (string apikey, string id, bool counts)

Add a new Interest Grouping.

MailChimp API Method:
lists/interest-grouping-add (string apikey, string id, string name, string type, array groups)

If interest groups for the List are not yet enabled, adding the first grouping will automatically turn them on.

Delete an existing Interest Grouping.

MailChimp API Method:
lists/interest-grouping-del (string apikey, int grouping_id)

This will permanently delete all contained interest groups and will remove those selections from all list members.

Update an existing Interest Grouping.

MailChimp API Method:
lists/interest-grouping-update (string apikey, int grouping_id, string name, string value)

Retrieve all of the lists defined for your user account.

MailChimp API Method:
lists/list (string apikey, struct filters, int start, int limit, string sort_field, string sort_dir)

Retrieve the locations (countries) that the list’s subscribers have been tagged to.

MailChimp API Method:
lists/locations (string apikey, string id)

Get the most recent 100 activities for particular list members.

MailChimp API Method:
lists/member-activity (string apikey, string id, array emails)

Get all the information for particular members of a list.

MailChimp API Method:
lists/member-info (string apikey, string id, array emails)

Get all of the list members for a list.

MailChimp API Method:
lists/members (string apikey, string id, string status, struct opts)

MailChimp API Method:
gallery/list (string apikey, struct opts)

PHP Stock Market API

Here’s a quick API script I put together to help monitor my stocks. It’s a PHP Stock Market API that uses the Yahoo! Finance API and allows you to retrieve up to 20 current data points for a particular symbol. It’s simple to use and doesn’t require any knowledge on how to implement or use the Yahoo! Finance API.

Looking to grab the latest stock market data? There’s a surprising lack of stock market APIs out there and even fewer that work consistently or affordable. Never fear, the PHP Stock Market API is here!

The PHP Stock Market API is a simple PHP class that uses the Yahoo! Finance API allowing you to retrieve up to 20 current data points for a particular symbol. It’s simple to implement and doesn’t require you to learn how to use the Yahoo! API.

UPDATE (Nov. 28, 2014, v1.3): getData now allows an array to pull multiple stocks at once (thanks @d3vit).
UPDATE (Jan. 27, 2014, v1.2): You can now also retrieve historical data (open, high, low, close, volume & adjusted close).

Download Now (Version 1.3) Fork on GitHub


PHP Stock Market API Usage

With just a few lines of code, you can easily retrieve 20 current data points. Here’s how it works:

<?php
require_once('class.stockMarketAPI.php');
?>

<h1>Current Stock Information for AAPL</h1>

<?php
$StockMarketAPI = new StockMarketAPI;
$StockMarketAPI->symbol = 'AAPL';
?>
<pre><?php print_r($StockMarketAPI->getData());?></pre>

<?php
$start = '01-01-2013';
$end = '01-07-2013';
?>
<h1>Historical Stock Information for AAPL (<?php echo $start ?> - <?php echo $end ?>)</h1>
<?php
$StockMarketAPI = new StockMarketAPI;
$StockMarketAPI->symbol = 'AAPL';
$StockMarketAPI->history = array(
  'start'    => $start,
  'end'    => $end,
  'interval' => 'd' // Daily
);
?>
<pre><?php print_r($StockMarketAPI->getData());?></pre>

<hr>

<h1>Stock Information for AAPL, MSFT, GOOGL</h1>
<?php
$StockMarketAPI = new StockMarketAPI;
$StockMarketAPI->symbol = array('AAPL', 'MSFT', 'GOOGL');
?>
<pre><?php print_r($StockMarketAPI->getData());?></pre>

Mozscape API PHP Class

Mozscape’s API is a little daunting to use with the amount of valuable information it can offer. Here’s a simple PHP class that allows you to easily access your site’s SEO metrics using the Mozscape API. A major benefit to the Mozscape API PHP Class is the ability to return detailed information on the response fields Mozscape provides.

Features

Download Now (Version 1.1) Fork on GitHub


Implementation

It’s pretty simple to use this class. Currently it’s pretty limited to the data it can provide in relation to what’s available through Mozscape’s API, but I do have plans on adding the rest of the available APIs later on.

That’s it, pretty simple huh?

Documentation

Here’s more detailed information on how to use the class. If you have any questions or suggestions, I’d love to hear them.

Mozscape URL Metrics API

urlMetrics($site_url, $sum_of_bit_flags)

To access the Mozscape URL Metrics API, you just need to provide the URL you want to retrieve data for and the type of data you want (the total sum of Bit Flags).

Mozscape Response Fields

responseFields($field, $return_value = '')

This is a great helper to get information on the various response fields that the Mozscape API provides, including the bit flag values, user-friendly names, slugs, and descriptions! See more information on Mozscape’s Response Fields here: http://apiwiki.seomoz.org/response-fields.

Mozscape Top Pages API

topPages($url, $offset = 0, $limit = 1000, $bits = 4)

This paid call returns the metrics about many URLs on a given subdomain. The top pages call can be accessed by the API call top-pages. A set of metrics can be requested by indicating them as bit flags in the $bits parameter. A page of urls with associated metrics is returned. The start record of the page can be specified using the $offset parameter. The size of the page can by specified using the $limit parameter. URLs are currently sorted by number of linking root domains.

A maximum of 1000 records can be retrieved per call. Limits over this value will result in a 400 Bad Request or 500 Internal Error response.

Currently only 10,000 pages may be retrieved using top-pages calls, in at least 10 calls.

See more on Mozscape’s Top Pages API here: http://apiwiki.seomoz.org/top-pages-api

Mozscape Required Attribution Link

attributionLink($type, $size, $img_dir = 'img/mozscape/')

This is good to use to stay compliant with the required Mozscape API’s attribution links. Provides easy output using their approved logo or icon with the required link.


Change Log

Version 1.1

  • Created a changelog file
  • Added an error message if the Curl request to the Mozscape API failed
  • Added the Mozscape Metadata API Calls
  • Added the Mozscape Top Pages API