Mad Mimi

Audience Import

POST to https://api.madmimi.com/audience_members with the following parameters:

Your Mad Mimi username
Your Mad Mimi api_key
A csv_file (which can be unstructured input)
(Optional) The name of the audience_list you want to import into

Sample input

The CSV file should contain a header row that contains column names like 'email', 'first name', 'last name'. Email is the only required column. Custom columns, like the car column in the example below, can be added and then used in promotions just like any other personalization tags.

An example of a CSV file:

    email,first name,last name,car
dave@example.com,Dave,Hoover,Ford
colin@example.com,Colin,Harris,Chevy

Importing into audience lists

Audience lists are also supported in a CSV file. Simply add a column titled 'add_list' that contains the name of the list you would like the email added to.

An example:

email,first name,last name,add_list
dave@example.com,Dave,Hoover,customer
colin@example.com,Colin,Harris,investor

Removing from audience lists

By adding a 'remove_list' to your column headings in your CSV file, you can tell Mad Mimi to remove certain email addresses from particular lists.

An example:

email,first name,last name,remove_list
dave@example.com,Dave,Hoover,customer
colin@example.com,Colin,Harris,investor

Suppression

Suppression is also supported in a CSV file. Simply add a column titled 'opt_out' that contains a 1 for suppress, 0 for unsuppress and is blank for no change

An example:

email,first name,last name,opt_out
dave@example.com,Dave,Hoover,1
colin@example.com,Colin,Harris,0
john@example.com,John,Davis,

In the example, Dave would be suppressed, Colin would be unsuppressed and John would remain (un)suppressed.

Ruby audience import sample code

require 'rubygems'
require 'httparty'
require 'hpricot'
class MadMimiImport
  include HTTParty
  base_uri 'https://api.madmimi.com'
  USERNAME = 'your@madmimi.username'
  API_KEY = '000your000api000key000'
  LIST_NAME = "the_name_of_the_list_to_import_into"
def run
  get_import_list # get the id of the list we want to import into from the name so we can use it for progress later
  puts "#{LIST_NAME} has an id of #{@list_id}"
  puts "Importing..."
  do_import
  puts "Import has started..."
  have_progress = false # let's see if we've got progress before, so we know when to stop polling
  while true do
    progress = get_progress # get the progress
    have_progress = true if progress > 0
    puts "Progress #{progress}%"
    break if have_progress && progress >= 100
    sleep 1 # sleep a bit so the import has time to progress
  end
  puts "Import complete"
end
def get_import_list
  lists_xml = self.class.get("/audience_lists/lists.xml?username=#{USERNAME}&api_key=#{API_KEY}")
  lists_doc = Hpricot(lists_xml.body)
  @list_id = (lists_doc/"list").detect { |list| list["name"] == LIST_NAME }["id"]
end
def do_import
  csv_file = IO.read("large_test_import.csv")
  self.class.post('/audience_members', :body => {
    :username => USERNAME,
    :api_key => API_KEY,
    :audience_list => LIST_NAME,
    :csv_file => csv_file,
  })
end
def get_progress
  progress_xml = self.class.get("/audience_lists/#{@list_id}/pending_total_progress.xml?username=#{USERNAME}&api_key=#{API_KEY}")
  progress_doc = Hpricot(progress_xml.body)
  (progress_doc/"progress").first.inner_html.to_f
rescue
  0
end
end
import = MadMimiImport.new
  import.run