Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jamesmartin/850261 to your computer and use it in GitHub Desktop.
Save jamesmartin/850261 to your computer and use it in GitHub Desktop.
Adding custom fields with multiple values to a subscriber
require 'rubygems'
require 'json'
custom_fields = [
{ :Key => 'memstatus', :Value => "{account_status}"},
{ :Key => 'memtype', :Value => "{user.member_type}"},
{ :Key => 'memsincedate', :Value => "{member_since.to_date}"},
{ :Key => 'memrenewaldate', :Value => "{user.account.renewal_date.to_date}"},
{ :Key => 'usertype', :Value => "{user_type}"},
#{ :Key => 'neighborhood group', :Value => "#{neighborhood_groups.join('||')}", :DataType => 'Multi-Options'},
#{ :Key => 'social group', :Value => "social_groups.join('||')", :DataType => 'Multi-Options'}
]
neighborhood_groups = %w[ a b c ]
neighborhood_groups.each {|value| custom_fields << {:Key => 'neighborhood group', :Value => "#{value}"}}
social_groups = %w[ 1 2 3 ]
social_groups.each {|value| custom_fields << {:Key => 'social group', :Value => "#{value}"}}
subscribers = [{ :EmailAddress => "{user.email}", :Name => "{user.last_name}, {user.first_name}", :CustomFields => custom_fields }]
puts JSON.generate(subscribers)
@jamesmartin
Copy link
Author

Gives the following output:

[{"CustomFields":[{"Value":"{account_status}","Key":"memstatus"},{"Value":"{user.member_type}","Key":"memtype"},{"Value":"{member_since.to_date}","Key":"memsincedate"},{"Value":"{user.account.renewal_date.to_date}","Key":"memrenewaldate"},{"Value":"{user_type}","Key":"usertype"},{"Value":"a","Key":"neighborhood group"},{"Value":"b","Key":"neighborhood group"},{"Value":"c","Key":"neighborhood group"},{"Value":"1","Key":"social group"},{"Value":"2","Key":"social group"},{"Value":"3","Key":"social group"}],"EmailAddress":"{user.email}","Name":"{user.last_name}, {user.first_name}"}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment