简体   繁体   中英

Google-app-script error invalid assignment left-hand side

Hello I'm getting trouble to find this error in google apps script. I reviewed my code a bunch of time and nothing. This code is to use in a webhook in a service that work with inbound marketing which there I have some pop-up forms to get users for my newsletter, and I want this subscribers to my Mail chimp account just to send updates about blog. So I'm using this code below to do it, but I'm getting this error. Sorry If I code wrong. The JSON source is like this https://github.com/ResultadosDigitais/rdocs/blob/master/rdstation_integration.json the md5Hash function I create to give the hash of a string.

Thanks a lot if anyone could help me!

//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);
 }
}

Error is caused by this line:

var mergeFields = ["FNAME" = nome];

Change it to:

var mergeFields = {"FNAME": nome};

Same for this code block:

bodyData.push([
  "email_address" = email,
  "status_if_new" = "subscribed",
  "status" = "subscribed",
  "merge_fields" = mergeFields
]);

Change it to

bodyData.push({
  "email_address": email,
  "status_if_new": "subscribed",
  "status": "subscribed",
  "merge_fields": mergeFields
});

Details about object literals in JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Object_literals

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM