Skip to content

Instantly share code, notes, and snippets.

@sebmih
Created November 8, 2013 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebmih/7367815 to your computer and use it in GitHub Desktop.
Save sebmih/7367815 to your computer and use it in GitHub Desktop.
This script will try adding multiple email addresses to a recipient list using the NL API.
require 'httparty'
require 'JSON'
url = 'https://sendgrid.com/api/newsletter/lists/email/add.json'
#the arrays containg email addreses and custom tags
emails = ['andrei@sendgridson2.com','andrejstg@gmai2l.com']
names = ['Andrei1','Andrei2']
array = []
#go through the emails array.
emails.each_with_index do |a,idx|
#created a hash that stores the email and name parameters of the larger 'data' param
hash = {
:email => a,
:name => names[idx]
}
#convert the hash to json and concatenate it with the 'data' param
array << hash.to_json
end
puts array
response = HTTParty.post url, :body => {
:api_user => 'username',
:api_key => 'password',
:list => 'TestSGlist',
:data => array
}
puts response.request.options
puts response.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment