簡體   English   中英

無法將電子郵件添加到Campaign Monitor API?

[英]Can't add email to Campaign Monitor API?

我正在嘗試創建一些簡單的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。 但是,當我嘗試添加電子郵件時,收到以下響應。

{“代碼” => 400,“消息” =>“未能反序列化您的請求。
請檢查文檔,然后重試。
錯誤字段:訂戶“}
400

當我更改get而不是put請求時,我的答復是:

{“代碼” => 1,“消息” =>“無效的電子郵件地址”}

我遵循了Campaign Monitor API上的文檔,因此我無法理解自己在做什么錯

看起來您已正確設置了所有內容,只需要將帖子的正文轉換為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寶石

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM