sendgrid-python icon indicating copy to clipboard operation
sendgrid-python copied to clipboard

Add Multiple Recipients from a csv file

Open MIKNOTAURO opened this issue 7 years ago • 12 comments

Feature request

It would be awesome (and a killer feature maybe) to have a method for add recipients from a csv file... maybe with 2 requests or with one request and a serialize data like json or xml

MIKNOTAURO avatar Feb 13 '18 12:02 MIKNOTAURO

Hi @MIKNOTAURO,

Thanks for the suggestion!

I will leave this open since even though it's now on our backlog, it's not likely to be implemented by SendGrid soon. However, if someone would like to submit a PR, that would be awesome :)

With Best Regards,

Elmer

thinkingserious avatar Feb 14 '18 20:02 thinkingserious

@MIKNOTAURO how do you see this working?

jonodrew avatar Feb 22 '18 15:02 jonodrew

@jonodrew @thinkingserious

Like this endpoint POST /contactdb/recipients but with a csv file something like this -> POST /contactdb/recipients_from_file or POST /contactdb/recipients_from_csv

And then with python like this

sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))

response = sg.client.contactdb.recipients_from_file.post(csv_file, list_id_optional=1, delimiter=',', clomuns='email', 'name'... )

Where

delimiter -> could be | or , or something else like in csv files columns -> could be useful to map the values between the csv file and sendgrid data structure of recipients and some optional parameters like list_id to also add those recipients to a list

The thing is that you have to deal with a binary files in a rest call.... which could be tricky but possible in some ways.

What do you think guys?

MIKNOTAURO avatar Feb 22 '18 17:02 MIKNOTAURO

@thinkingserious I will like to work on this

RamolaWeb avatar Oct 08 '18 20:10 RamolaWeb

Thank you @RamolaWeb!

thinkingserious avatar Oct 08 '18 23:10 thinkingserious

Is this still open?

jonodrew avatar May 19 '20 12:05 jonodrew

@jonodrew Yes, still open.

childish-sambino avatar Jul 10 '20 20:07 childish-sambino

I'm going to have a little go at this then please

jonodrew avatar Jul 10 '20 21:07 jonodrew

Forgive my ignorance on this, but the first part of this request

Like this endpoint POST /contactdb/recipients but with a csv file something like this -> POST /contactdb/recipients_from_file or POST /contactdb/recipients_from_csv

is out of our control, right? This isn't the library for updating the actual Sendgrid API?

In which case I plan to add the proposed method contacts_from_csv and implement by iterating over the file and PUTting the requests one-by-one to api.sendgrid.com/v3/marketing/contacts (documented here: https://sendgrid.com/docs/API_Reference/api_v3.html)

Does this approach sound okay?

jonodrew avatar Jul 11 '20 10:07 jonodrew

In fact, on closer inspection, it looks like the web API already has this capability: you just have to PUT to /marketing/contacts/imports

So:

  1. There would be a call to that endpoint. The endpoint needs a mapping of the columns in the csv to the id of the field.
  2. The endpoint returns a URL to upload the file to, along with headers that need to be included

jonodrew avatar Jul 11 '20 14:07 jonodrew

In fact, on closer inspection, it looks like the web API already has this capability: you just have to PUT to /marketing/contacts/imports

So:

  1. There would be a call to that endpoint. The endpoint needs a mapping of the columns in the csv to the id of the field.

  2. The endpoint returns a URL to upload the file to, along with headers that need to be included

At the moment of my post, this feature was not available, but you are right, we need an endpoint at the SendGrid API level (I’m not sure if now it’s available, but should be :$)

Do you have any work around this and need some help/testers ?

MIKNOTAURO avatar Jul 11 '20 15:07 MIKNOTAURO

Thank you for your kind offer @MIKNOTAURO ! I guess it would be helpful if, as a user, you could tell me what headings you'd use in the CSV, and why?

jonodrew avatar Jul 11 '20 15:07 jonodrew