Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add/remove contacts to a list via new marketing API? #456

Closed
netwire88 opened this issue Jan 12, 2021 · 5 comments
Closed

How to add/remove contacts to a list via new marketing API? #456

netwire88 opened this issue Jan 12, 2021 · 5 comments
Labels
status: duplicate duplicate issue

Comments

@netwire88
Copy link

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?

@rickychilcott
Copy link

#391 might be helpful to you. This does need better documentation

@netwire88
Copy link
Author

netwire88 commented Jan 12, 2021

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)

@rickychilcott
Copy link

rickychilcott commented Jan 12, 2021

Adding a user to a list without changing anything else about that should be something like:

contacts = [{ email: "[email protected]"}]
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)

@netwire88
Copy link
Author

netwire88 commented Jan 12, 2021

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

@thinkingserious thinkingserious added the status: duplicate duplicate issue label Jan 12, 2021
@thinkingserious
Copy link
Contributor

Please be sure to vote on this issue to help move the priority up. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate duplicate issue
Projects
None yet
Development

No branches or pull requests

3 participants