您好我在谷歌应用脚本中发现此错误时遇到了麻烦。我审查了我的代码一堆时间,没有。此代码用于与入站营销一起使用的服务中的webhook,我有一些弹出窗体可以让用户收到我的简报,我希望这个订阅者能够通过我的Mail黑猩猩帐户发送有关博客的更新。所以我使用下面的代码来做到这一点,但我收到了这个错误。对不起如果我编码错了。 JSON源是这样的https://github.com/ResultadosDigitais/rdocs/blob/master/rdstation_integration.json 我创建的md5Hash函数用于给出字符串的哈希值。
非常感谢,如果有人能帮助我的话!
//receive the request
function doPost(e){
return mcResponse(e);
}
//Send information to MC
function mcResponse(n){
var email = n.parameter["leads[email]"];
var nome = n.parameter["leads[name]"];
var hash = md5Hash(email);
try {
var bodyData = [];
var mergeFields = ["FNAME" = nome];
bodyData.push([
"email_address" = email,
"status_if_new" = "subscribed",
"status" = "subscribed",
"merge_fields" = mergeFields
]);
var headers = {
'Content-type': 'application/json',
'Authorization': 'apikey ' + API_KEY_MC
};
var options = {
'method': 'PUT',
'headers': JSON.stringify(headers),
'payload': JSON.stringify(bodyData)
};
var response = UrlFetchApp.fetch(MC_URL + LIST_ID + '/members/' + hash, options);
return ContentService.createTextOutput(response.getContentText());
} catch(e){
return ContentService.createTextOutput(e);
}
}
答案 0 :(得分:2)
错误是由此行引起的:
var mergeFields = ["FNAME" = nome];
将其更改为:
var mergeFields = {"FNAME": nome};
此代码块相同:
bodyData.push([
"email_address" = email,
"status_if_new" = "subscribed",
"status" = "subscribed",
"merge_fields" = mergeFields
]);
将其更改为
bodyData.push({
"email_address": email,
"status_if_new": "subscribed",
"status": "subscribed",
"merge_fields": mergeFields
});
有关JavaScript中对象文字的详细信息:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Object_literals