0

I don't know if this is gem/api related question or implementation, but after deleting a member from a list, I can't add him again. I'm obtaining that

is already a list member. Use PUT to insert or update list members.

I am using the following methods to add members from a list:

class SubscribeToNewsletterService
 def initialize(user)
  @user = user
  @gibbon = Gibbon::Request.new(api_key: ENV['MAILCHIMP_API_KEY'])
  @list_id = ENV['MAILCHIMP_LIST_ID']
end

def call
@gibbon.lists(@list_id).members.create(
  body: {
    email_address: @user.email,
    status: "subscribed",
    merge_fields: {
      FNAME: @user.first_name,
      LNAME: @user.last_name,
     }
   }
 )
 end
end
  • How did you delete the member from the list? What was the API response? – Tom Lord Nov 29 '17 at 16:25
  • i delete the member in my application web not in gibbon , i thing it messing something in my method but i'm rookie on rails. this answer i have in my log : XXXX@gmail.com is already a list member. Use PUT to insert or update list members. – Florian Lahitte Nov 29 '17 at 16:26
  • Message: the server responded with status 400 @title="Member Exists", @detail="XXXXXX@hotmail.fr is already a list member. Use PUT to insert or update list members. – Florian Lahitte Nov 29 '17 at 16:33
  • The error is that the member still exists **in gibbon**. You're not deleting the user from the third party, hence the error. You need to send a `DELETE` API request, as part of the controller action or whatever. See the documentation here: http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#delete-delete_lists_list_id_members_subscriber_hash – Tom Lord Nov 29 '17 at 16:43
  • You can see all API calls handled by Gibbon here: http://developer.mailchimp.com/documentation/mailchimp/reference/overview/ – Tom Lord Nov 29 '17 at 16:44
  • Also, looking at [the `gibbon` docs](https://github.com/amro/gibbon), you could consider using `upsert` if you don't want to delete users from mailchimp. – Tom Lord Nov 29 '17 at 16:46
  • sorry i'm new and it's was hard to me to do this method for create user after we sign up but what is upsert how i can put ? in new method or something else ? – Florian Lahitte Nov 29 '17 at 17:11
  • `upsert` means "Update or Insert". In other words, if you try to `upsert` (as opposed to `create`) a user *who already exists*, then it won't throw an error. – Tom Lord Nov 29 '17 at 17:36
  • The question, really, is: Do you want to delete users from `mailchimp` if you delete them from your application?? If yes, then implement the `delete` action. If no, then use `upsert` instead of `create`. – Tom Lord Nov 29 '17 at 17:37
  • I take the first choice. so to implement delete action i must to do another method ? – Florian Lahitte Nov 29 '17 at 17:42
  • Yes. As stated above, you need to trigger a `delete` request over the API. If you're still having difficulty, please include any additional information (e.g. errors) in the body of your post, not buried here in the comments, so that others will see it easily. – Tom Lord Nov 29 '17 at 17:48

0 Answers0