How can I check if email is a member?
SupremeA opened this issue · 2 comments
Hello, I am using the Mailchimp API v.3.0 I see that there is a /search-members endpoint.
https://developer.mailchimp.com/documentation/mailchimp/reference/search-members/
I have the following code to search for a member but I cant get this endpoint to work.
list_id = ENV['MAILCHIMP_LIST_ID']
@gibbon = Gibbon::Request.new(api_key: ENV['mailchimp_api_key'], symbolize_keys: true)
@member_id = Digest::MD5.hexdigest(params[:stripeEmail]
@member_info = @gibbon.lists(list_id).members(@member_id).retrieve.body[:status]
This code works to identify a member IF they ARE in the list but it gets a 404 error response if the email is NOT in the list and it crashes my app. I want to use the search-member endpoint to get a good response for an email NOT in the list.
Sorry it took me a little while to respond, @SupremeA. Gibbon throws errors for API responses that are not "success." Wrap the call in a begin/rescue and look for the 404 and handle it as a "not subscribed." That's how I would handle this.
Worked like a charm! Thanks