You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Upgrading to use new Marketing API contacts list #391
Reacted by Andy Kelk, Ben Umali, Lindsay, Kevin Lang, Kamran Pirwani, Tiago Alves, Krystan HuffMenne, Dave Sullivan, Victor Bordo, Jan Grodowski and 21 more
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...
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: 't@h.com}]list_ids = ["2984y3u32-2334932-34344"] # some crazy long UUID of the list you'retryingtosendthesecontactsto(youcangrabitfromtheURLbaronthedashboard)(not theoldIntegerIDs)body={list_ids: list_ids,contacts: users}response=sg.client.marketing.contacts.put(request_body: body)Rails.logger.debugresponse.status_codeRails.logger.debugresponse.bodyRails.logger.debugresponse.headers
Reacted by Elie Dutheil, Elmer Thomas, Ricky Chilcott, Nagesh, Jack Collins, romanos, sharataka, jovanialferez, jibiel, Pietro Degrazia and 2 more
@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:
#initialize your client
@client = SendGrid::API.new(api_key: YOUR_API_KEY).client
#Get a single contact by its ID
#GET /marketing/contacts/{id}
@client.marketing.contacts.send(id).get
#delete a contact
#DELETE /marketing/contacts
@client.marketing.contacts.delete({query_params: {ids: id}})
#search for a contact
#POST /marketing/contacts/search
@client.marketing.contacts.search.post(request_body: {"query"=>"email = '#{email}'"})
#ETC
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.
Reacted by Tanner Hallman, João Ferreira Loff, Elmer Thomas, Ricky Chilcott, CPU, Jack Collins, Sohee_Lim, John Athayde, netwire88, jibiel and 2 more
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
Reacted by João Ferreira Loff, Camilo Hollanda, Jeff Schroeder, romanos, Greg Leuch, Kevin Dolch, netwire88, Nick McCullum, daichi0410, David Mears and 1 more
@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"])defsendgrid_custom_field_definitions@sendgrid_custom_field_definitions ||=
$sg
.marketing.field_definitions.get.parsed_body.fetch(:custom_fields)enddeftransform_custom_fields(contact_groups)contact_groups.mapdo |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_keysdo |key|
field_definition=sendgrid_custom_field_definitions.finddo |fd|
fd[:name].to_s == key.to_sendfield_definition[:id]endtransformed_contactendendusers_with_custom_fields=[{first_name: "Ricky",last_name: "Chilcott",email: "r@c.com, custom_fields: {"age" => 30, "ice_cream_flavor" => "chocolate"}}]list_ids = ["2984y3u32-2334932-34344"] # some crazy long UUID of the list you"retryingtosendthesecontactsto(youcangrabitfromtheURLbaronthedashboard)(not theoldIntegerIDs)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.debugresponse.status_codeRails.logger.debugresponse.bodyRails.logger.debugresponse.headers
I've made it rely on SendGrid's field_definitions endpoint to lookup the appropriate mappings.
Hoping this helps someone else. Ideally, sendgrid-ruby would do this transformation for us -- ideally not even relying on us wrapping custom fields in their own sub-object.
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.
Activity
tannerhallman commentedon Feb 6, 2020
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:
ooochie commentedon Feb 6, 2020
@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.
thinkingserious commentedon Mar 19, 2020
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
tannerhallman commentedon Mar 19, 2020
Wait so you are not going to be building support for the new marketing campaign into this library? Is SendGrid dropping support for Ruby?
childish-sambino commentedon Mar 20, 2020
@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.
kjohnston commentedon Mar 22, 2020
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.
rickychilcott commentedon May 6, 2020
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:
I've made it rely on SendGrid's field_definitions endpoint to lookup the appropriate mappings.
Hoping this helps someone else. Ideally,
sendgrid-rubywould do this transformation for us -- ideally not even relying on us wrapping custom fields in their own sub-object.netwire88 commentedon Jan 12, 2021
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.
JohnLegrandRichards commentedon Aug 10, 2021
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.
david-mears-2 commentedon Oct 21, 2021
@JohnLegrandRichards I think you are right that this is just a documentation issue. Did you make any progress on this?