Created
November 8, 2013 08:08
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
require 'JSON' | |
url = 'https://sendgrid.com/api/newsletter/lists/email/add.json' | |
#the arrays containg email addreses and custom tags | |
emails = ['[email protected]','[email protected]'] | |
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