2015-01-02 145 views
3

我有一些真正的困難嘗試發送多個電子郵件地址在JSON到sendgrid API。SendGrid添加多個電子郵件地址到營銷電子郵件API

這裏是我的代碼,一個電子郵件地址,工作原理:

@result = HTTParty.post("https://api.sendgrid.com/api/newsletter/lists/email/add.json", 
:body => { :list => "#{@survey.name}_#{@survey.id}", :data => '{ "name": "John Smith", "email": "[email protected]" }', :api_user => 'XXXXX', :api_key => 'XXXXX'}) 

但是在Ruby使用:數據後的屬性如何添加其他電子郵件地址?

下不工作 - 生活就太容易笑

:data => '[{"email" => "[email protected]"},{"email" => "[email protected]"}]' 

OR

:data => '{[{"email" => "[email protected]"},{"email" => "[email protected]"}]}' 

顯然SendGrid預計下....

data[]={"email" => "[email protected]"}&data[]={"email" => "[email protected]"} 

我如何可以在rails中創建一個post參數來做到這一點?!?

回答

2

你可以創建你的:data PARAM作爲JSONs數組,像這樣:

:data => ['{ "name" : "Foo Bar", "email" : "[email protected]" }','{ "name" : "Jon Snow", "email" : "[email protected]" }']

+0

真棒 - 太感謝你了,我真的很感謝你在這個時候。 –