【问题标题】:Can't add email to Campaign Monitor API?无法将电子邮件添加到 Campaign Monitor API?
【发布时间】:2016-01-12 20:44:48
【问题描述】:

我正在尝试创建一些简单的 Ruby 代码来使用 Campaign Monitor API 添加电子邮件。下面是我的代码。

require 'httparty'
require 'json'

def request
    url = 'https://api.createsend.com/api/v3.1/subscribers/MYLISTID.json'
    auth = {:username => 'MYAPIKEY', :password => 'x'}
    response = HTTParty.post(url,
                  :basic_auth => auth, :body => {
                      'EmailAddress' => 'mike@hotmail.com',
                      'Name' => 'Test',
                      'Resubscribe' => true,
                      'RestartSubscriptionBasedAutoresponders' => true
                  })
    puts response
    puts response.code
end
request

我可以连接 API。但是,当我尝试添加电子邮件时,我收到以下回复。

{"Code"=>400, "Message"=>"无法反序列化您的请求。
请检查文档并重试。
错误字段:订阅者"}
400

当我将请求更改为 get 而不是 put 我的回答是:

{"Code"=>1, "Message"=>"无效的电子邮件地址"}

我不明白我做错了什么,因为我遵循了Campaign Monitor API 上的文档

【问题讨论】:

    标签: ruby api httparty campaign-monitor


    【解决方案1】:

    看起来您已经正确设置了所有内容,您只需要将帖子的正文转换为 json 字符串。

      response = HTTParty.post(url,
        :basic_auth => auth, :body => {
           'EmailAddress' => 'mike@hotmail.com',
           'Name' => 'Test',
           'Resubscribe' => true,
           'RestartSubscriptionBasedAutoresponders' => true
         }.to_json)
    

    我想指出,还有一个 Campaign Monitor API gem 可以为您完成所有这些工作。

    Campaign Monitor API Gem

    【讨论】:

      猜你喜欢
      • 2016-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-02
      • 2012-02-17
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多