Method: Mailchimp::Lists#subscribe

Defined in:
lib/mailchimp/api.rb

#subscribe(id, email, merge_vars = nil, email_type = 'html', double_optin = true, update_existing = false, replace_interests = true, send_welcome = false) ⇒ Hash

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!

Parameters:

  • id (String)

    the list id to connect to. Get by calling lists/list()

  • email (Hash)

    a struct with one of the following keys - failing to provide anything will produce an error relating to the email address. Providing multiples and will use the first we see in this same order.

    • String

      email an email address - for new subscribers obviously this should be used

    • String

      euid the unique id for an email address (not list related) - the email “id” returned from listMemberInfo, Webhooks, Campaigns, etc.

    • String

      leid the list email id (previously called web_id) for a list-member-info type call. this doesn’t change when the email address changes

  • merge_vars (Hash) (defaults to: nil)

    optional merges for the email (FNAME, LNAME, <a href=“kb.mailchimp.com/article/where-can-i-find-my-lists-merge-tags target=”_blank“>etc.</a>) (see examples below for handling ”blank“ arrays). Note that a merge field can only hold up to 255 bytes. Also, there are a few ”special“ keys:

    • String

      new-email set this to change the email address. This is only respected on calls using update_existing or when passed to listUpdateMember().

    • Array

      groupings of Interest Grouping structs. Each should contain:

      - [Int] id Grouping "id" from lists/interest-groupings (either this or name must be present) - this id takes precedence and can't change (unlike the name)
      - [String] name Grouping "name" from lists/interest-groupings (either this or id must be present)
      - [Array] groups an array of valid group names for this grouping.
      
    • String

      optin_ip Set the Opt-in IP field. Abusing this may cause your account to be suspended. We do validate this and it must not be a private IP address.

    • String

      optin_time Set the Opt-in Time field. Abusing this may cause your account to be suspended. We do validate this and it must be a valid date. Use - 24 hour format in <strong>GMT</strong>, eg “2013-12-30 20:30:00” to be safe. Generally, though, anything strtotime() understands we’ll understand - <a href=“us2.php.net/strtotime” target=“_blank”>us2.php.net/strtotime</a>

    • Hash

      mc_location Set the member’s geographic location either by optin_ip or geo data.

      - [String] latitude use the specified latitude (longitude must exist for this to work)
      - [String] longitude use the specified longitude (latitude must exist for this to work)
      - [String] anything if this (or any other key exists here) we'll try to use the optin ip. NOTE - this will slow down each subscribe call a bit, especially for lat/lng pairs in sparsely populated areas. Currently our automated background processes can and will overwrite this based on opens and clicks.
      
    • String

      mc_language Set the member’s language preference. Supported codes are fully case-sensitive and can be found <a href=“kb.mailchimp.com/article/can-i-see-what-languages-my-subscribers-use#code” target=“_new”>here</a>.

    • Array

      mc_notes of structs for managing notes - it may contain:

      - [String] note the note to set. this is required unless you're deleting a note
      - [Int] id the note id to operate on. not including this (or using an invalid id) causes a new note to be added
      - [String] action if the "id" key exists and is valid, an "update" key may be set to "append" (default), "prepend", "replace", or "delete" to handle how we should update existing notes. "delete", obviously, will only work with a valid "id" - passing that along with "note" and an invalid "id" is wrong and will be ignored.
      
  • email_type (String) (defaults to: 'html')

    optional email type preference for the email (html or text - defaults to html)

  • double_optin (Bool) (defaults to: true)

    optional flag to control whether a double opt-in confirmation message is sent, defaults to true. Abusing this may cause your account to be suspended.

  • update_existing (Bool) (defaults to: false)

    optional flag to control whether existing subscribers should be updated instead of throwing an error, defaults to false

  • replace_interests (Bool) (defaults to: true)

    optional 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)

  • send_welcome (Bool) (defaults to: false)

    optional 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.

Returns:

  • (Hash)

    the ids for this subscriber

    • String

      email the email address added

    • String

      euid the email unique id

    • String

      leid the list member’s truly unique id



1195
1196
1197
1198
# File 'lib/mailchimp/api.rb', line 1195

def subscribe(id, email, merge_vars=nil, email_type='html', double_optin=true, update_existing=false, replace_interests=true, send_welcome=false)
    _params = {:id => id, :email => email, :merge_vars => merge_vars, :email_type => email_type, :double_optin => double_optin, :update_existing => update_existing, :replace_interests => replace_interests, :send_welcome => send_welcome}
    return @master.call 'lists/subscribe', _params
end