Sendgrid-python: Add Multiple Recipients from a csv file

Created on 13 Feb 2018  路  12Comments  路  Source: sendgrid/sendgrid-python

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

hard work in progress community enhancement

Most helpful comment

@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?

All 12 comments

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

@MIKNOTAURO how do you see this working?

@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?

@thinkingserious I will like to work on this

Thank you @RamolaWeb!

Is this still open?

@jonodrew Yes, still open.

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

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?

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

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鈥檓 not sure if now it鈥檚 available, but should be :$)

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

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?

Was this page helpful?
0 / 5 - 0 ratings