I'd like to work with mailchimp templetes with Ruby. I installed gem mailchimp-api and tried this:
mailchimp = Mailchimp::API.new(ENV['MAILCHIMP_API_KEY'])
lists = mailchimp.templates.list
list = lists['data']
puts list
It returns lists = Hash (3 elements): 'user'= Empty Array, 'gallery'= Empty Array, 'base'= Empty Array
, and as the result list = nil
.
I installed gem gibbon and tried this:
gibbon = Gibbon::Request.new(api_key: ENV['MAILCHIMP_API_KEY'])
templates = gibbon.templates.retrieve(params: {type: 'user'})
templates['templates'].each do |template|
if template['name'] == 'my_template'
id = template['id']
I get the template id, but gibbon.templates.info(template_id: id)
returns # with @api_endpoint=nil
. How can I recieve the template source and used it?
Many many thanks.
I found the solution. Mailchimp account can be linked with mandrill account to send transactional mails. The solution is to clone template from mailchimp to mandrill and use mandrill-api gem to load template body, like this:
mandrill = Mandrill::API.new(ENV["SMTP_PASSWORD"])
body = mandrill.templates.render(template_name, [], vars )["html"]