-
Notifications
You must be signed in to change notification settings - Fork 323
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
Upgrading to use new Marketing API contacts list #391
Comments
Any updates on this? There's no documentation on the new Marketing campaigns and I'm pulling my hair out. Bout to rage quit and rewrite app using Mailchimp. It's been 6 months... Update: I did find this https://sendgrid.com/docs/API_Reference/api_v3.html contacts which doesn't appear to be documented very well. I still can't get much to work with it though. Another Update: I finally, after guessing a lot, got the contacts uploading to a list using the new Marketing. See my example for those poor souls after me: sg = SendGrid::API.new(api_key: ENV["SENDGRID_API_KEY"])
users = [{first_name: 'Tanner', last_name: 'Hallman', email: '[email protected]}]
list_ids = ["2984y3u32-2334932-34344"] # some crazy long UUID of the list you're trying to send these contacts to (you can grab it from the URL bar on the dashboard) (not the old Integer IDs)
body = {list_ids: list_ids, contacts: users}
response = sg.client.marketing.contacts.put(request_body: body)
Rails.logger.debug response.status_code
Rails.logger.debug response.body
Rails.logger.debug response.headers |
@tannerhallman I, too, have been waiting for updates here. I ended up moving forward using this gem as-is, but writing an intermediate layer in my own app to access the new endpoints. The way this gem is written allows you to chain the methods together to access the endpoint you need, so you can just initialize your client and go from there, using the API docs you referenced under "NEW MARKETING CAMPAIGNS." Here's what I mean:
This API still leaves a lot to be desired and seems like it's not quite finished, but this is working for me in the interim. |
Hello @justinkchen, @tannerhallman and @ooochie, First, BIG THANKS to @tannerhallman and @ooochie for posting solutions!! Secondly, to answer @justinkchen, pull requests to add this feature are welcome and will be reviewed based on priority, but Twilio SendGrid is not actively building new functionality for the library. With best regards, Elmer |
Wait so you are not going to be building support for the new marketing campaign into this library? Is SendGrid dropping support for Ruby? |
@tannerhallman No, not dropping support for Ruby or this library. Just that building new functionality here is lower on the priority list at this time. |
I'm looking to come back to SendGrid for the marketing contacts, lists, segments and automation as it's something I can't get from Mailgun, Postmark or MailChimp. It looks like the API documentation for these endpoints is coming together. I'm happy to see a Ruby gem and appreciate the company-supported, community-built, approach here - everyone has to prioritize. But, I have to voice that without some more company support you're forcing busy people to decide between contributing to this project vs. hand-rolling only what they need in isolation. Please consider allocating some more Twilio SendGrid resource to the project to reduce the barrier to (re-)entry. |
If someone comes along and wants to be able to upload custom fields using @tannerhallman's code, you'll need to do a bit more work: $sg = SendGrid::API.new(api_key: ENV["SENDGRID_API_KEY"])
def sendgrid_custom_field_definitions
@sendgrid_custom_field_definitions ||=
$sg
.marketing
.field_definitions
.get
.parsed_body
.fetch(:custom_fields)
end
def transform_custom_fields(contact_groups)
contact_groups.map do |contact|
transformed_contact = contact.dup
# Convert from "custom_field_name" to sendgrid"s custom field "id"
transformed_contact[:custom_fields] =
transformed_contact[:custom_fields]
.transform_keys do |key|
field_definition =
sendgrid_custom_field_definitions.find do |fd|
fd[:name].to_s == key.to_s
end
field_definition[:id]
end
transformed_contact
end
end
users_with_custom_fields = [{first_name: "Ricky", last_name: "Chilcott", email: "[email protected], custom_fields: {"age" => 30, "ice_cream_flavor" => "chocolate"}}]
list_ids = ["2984y3u32-2334932-34344"] # some crazy long UUID of the list you"re trying to send these contacts to (you can grab it from the URL bar on the dashboard) (not the old Integer IDs)
users_with_transformed_custom_fields = transform_custom_fields(users_with_custom_fields)
body = {list_ids: list_ids, contacts: users_with_transformed_custom_fields}
response = sg.client.marketing.contacts.put(request_body: body)
Rails.logger.debug response.status_code
Rails.logger.debug response.body
Rails.logger.debug response.headers I've made it rely on SendGrid's field_definitions endpoint to lookup the appropriate mappings. Hoping this helps someone else. Ideally, |
Any update on the documentation? This https://github.com/sendgrid/sendgrid-ruby/blob/main/USAGE.md#contactdb looks outdated. I get 403 access forbidden error. |
This seems to be just a documentation issue. Chaining the methods through the client is all there. It just seems to not be well documented in the example folders. I will take the time this week to add a new campaigns folder in the documentation as well as a nested contacts folder. I will then include examples so people stop getting confused. |
@JohnLegrandRichards I think you are right that this is just a documentation issue. Did you make any progress on this? |
Issue Summary
I'm wondering what the timeline is expected to be for the sendgrid-ruby gem to support the Marketing Campaign v2?
Steps to Reproduce
N/A
Technical details:
The text was updated successfully, but these errors were encountered: