Closed netwire88 closed 3 years ago
Thanks @rickychilcott , I read through that, but the example is how to create a contact & add it to a list at the same time. I'm trying to figure out how to add/remove contacts to/from lists without updating contact info. Any ideas?
Essentially, how to translate DELETE /marketing/lists/{id}/contacts. (https://sendgrid.api-docs.io/v3.0/lists/remove-contacts-from-a-list) to sg.client.marketing....
format?
So far, I can retrieve a list
sg.client.marketing.lists._(list_id).get
But delete a contact doesn't work, it deletes the entire list instead of a single contact in a list:
sg.client.marketing.lists._(list_id).delete(contact_ids: contact_id)
Adding a user to a list without changing anything else about that should be something like:
contacts = [{ email: "abc@1234.com"}]
list_ids = ["abcd"]
response = sg.client.marketing.contacts.put(request_body: {list_ids: list_ids, contacts: contacts})
Note, if the email address does not exist, it will create a new contact.
Regarding deleting a contact from a list, I havent' done it myself.
The code you wrote does look close (e.g. sg.client.marketing.lists._(list_id).delete(contact_ids: contact_id)
).
But since that URL you linked to is DELETE /marketing/lists/{id}/contacts
does the following work:
sg.client.marketing.lists._(list_id).contacts.delete(contact_ids: contact_id)
Thanks @rickychilcott , great ideas!
It turns out the correct formatting for removing a contact from a list is:
sg.client.marketing.lists._(list_id).contacts.delete(query_params: {"contact_ids": contact_id})
I found some examples of similar API calls via https://github.com/sendgrid/sendgrid-ruby/blob/main/examples/suppression/suppression.rb
Please be sure to vote on this issue to help move the priority up. Thanks!
There doesn't seem to be any documentation on how to add/remove contacts to a list via the new marketing API? Is there a gem wrapper around this https://sendgrid.api-docs.io/v3.0/lists/remove-contacts-from-a-list?