Javascript + MailChimp API 订阅 [英] Javascript + MailChimp API subscribe

查看:28
本文介绍了Javascript + MailChimp API 订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提出此请求时:

// Subscribe a new account holder to a MailChimp list
function subscribeSomeoneToMailChimpList()
{
  var options =
  {
    "apikey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "id": "xxxxxx",
    "email":
    {
      "email": "me@example.com"
    },
    "send_welcome": false
  };
  var mcSubscribeRequest = UrlFetchApp.fetch("https://us4.api.mailchimp.com/2.0/lists/subscribe.json", options);
  var mcListObject = Utilities.jsonParse(mcSubscribeRequest.getContentText());
}

返回此响应:

https://us4.api.mailchimp.com/2.0/lists/subscribe 请求失败.json 返回代码 500.截断的服务器响应:{"status":"error","code":-100,"name":"ValidationError","error":"您必须指定一个 apikey 值"}(使用 muteHttpExceptions 选项检查完整响应)(第 120 行,文件v2")

Request failed for https://us4.api.mailchimp.com/2.0/lists/subscribe.json returned code 500. Truncated server response: {"status":"error","code":-100,"name":"ValidationError","error":"You must specify a apikey value"} (use muteHttpExceptions option to examine full response) (line 120, file "v2")

第 120 行是调用 UrlFetchApp.fetch 的行.

Line 120 is the line on which UrlFetchApp.fetch is called.

API 密钥有效(我已经使用不包含关联数组的更简单的 API 调用进行了测试).当我将 API 密钥直接附加到基本 URL 并将其从 options 中删除时,我收到一条错误消息,指出列表 ID 无效.然后,当我将列表 ID 直接附加到基本 URL 并将其从 options 中删除时,我收到一条错误消息,指出电子邮件地址必须采用关联数组形式.

The API key is valid (I have tested with simpler API calls that don't include associative arrays). When I append the API key directly to the base URL and remove it from the options, I get an error saying that the list ID is invalid. When I then append the list ID directly to the base URL and remove it from options, I get an error saying that the email address must be in associative array form.

我的问题是:使用上述格式,如何发送包含关联数组的请求?

My question is: Using the above format, how does one send requests that contain associative arrays?

可以在此处找到相关的 API 文档.

The relevant API documentation can be found here.

推荐答案

经过进一步研究 &修补,我能够解决这个问题:

After further research & tinkering, I was able to solve this:

https://<dc>.api.mailchimp.com/2.0/lists/subscribe.json?apikey=<my_api_key>&id=<my_list_id>&email[email]=test@test.com&merge_vars[FNAME]=John&merge_vars[LNAME]=Doe&double_optin=false&send_welcome=false

应替换为 API 密钥中破折号后的部分.例如us1"、us2"、uk1"等

Where <dc> should be replaced with the portion after the dash in your API Key. e.g. "us1", "us2", "uk1", etc.

这篇关于Javascript + MailChimp API 订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆