SendGrid将多个电子邮件地址添加到Marketing Email API

时间:2015-01-02 08:13:39

标签: ruby-on-rails ruby sendgrid httparty

我真的很难尝试将json中的多个电子邮件地址发送到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": "john@smith.com" }', :api_user => 'XXXXX', :api_key => 'XXXXX'})

但是在使用:data post属性的ruby中,如何添加其他电子邮件地址?

以下不做工作 - 生活太容易了lol

:data => '[{"email" => "nick@sendgrid.com"},{"email" => "jane@example.com"}]'

OR

:data => '{[{"email" => "nick@sendgrid.com"},{"email" => "jane@example.com"}]}'

显然SendGrid需要以下内容......

data[]={"email" => "nick@sendgrid.com"}&data[]={"email" => "jane@example.com"}

如何在rails中创建post参数呢?!?

1 个答案:

答案 0 :(得分:2)

您可以将:data param创建为JSON数组,如下所示:

:data => ['{ "name" : "Foo Bar", "email" : "foo@bar.com" }','{ "name" : "Jon Snow", "email" : "jon@snow.com" }']