0

I've created a test list in MailChimp and I added 2 subscribers.

I created a Ruby script that will retrieve emails of all subscribers with the help of gibbon gem.

The problem is that I'm the beginner in Ruby and I'm still really not confident with syntax.

Here's the code

require 'gibbon'
require 'byebug'

def mailchimp
  gibbon = Gibbon::Request.new(api_key:"my-api-key")
  gibbon.timeout = 10
  gibbon.lists("my_list_id").members.retrieve
end

debugger
mailchimp

When I test this in debugger with mailchimp.body, I can see that I get response, but it's in hash and with tons of information, while I only need to get email_address.

How can I dig or loop through this hash and only return email_address ?

Seinfeld
  • 433
  • 7
  • 24

1 Answers1

1

You can restrict the request to only the fields you'd like to see. Only retrieve emails for fetched lists:

response = gibbon.lists("my_list_id").members.retrieve(params: {"fields": "members.email_address"})

With that response body you can call keys to see what fields are available to you. A little less noise than printing out the entire body in IRB.


Related section in the Gibbon Docs

csexton
  • 24,061
  • 15
  • 54
  • 57
  • How to fetch multiple fields of specific member? like email and id? I tried `gibbon.lists(list_id).members(member_id).retrieve(params: {"fields": "email_address, id"})` but it doesn't worked – Gagan Gami Mar 01 '19 at 10:50