0
function doGet(e){
  var p = e.parameters;
  try {
    if ("username" in p) { // user info get
      let id = p.ID;
      let username = p.username;
      let time = p.time;
      let email = p.email;
      let roles = p.roles;
      let value = [id,username,time,email,roles];
      userSheet.appendRow(value);
      userSheet.getRange("F38").setValue(username) // This executes correctly;
      return ContentService.createTextOutput(username);
    }
  } catch (e){
    return ContentService.createTextOutput("Error: " + e.message);
  }
}

I am sending wordpress user data to my google app script API so it can be stored in the sheet.

However, the rows are like enter image description here

If I execute appendRow() like

function test(){
  let id =23;
  let idd = "23";
 userSheet.appendRow([id,idd]);
}

The data is correctly inserted. Also if I insert the data from GET by setValue

userSheet.getRange("F38").setValue(username) // This executes correctly;

there is no problem either.

So what is wrong with my code?

P.S. This question is related: Google Apps Script as Web App: problems with doPost(). Originally I intended to POST user data to my API, however, I can't solve the problem described in this question, so I have to use GET.

shenkwen
  • 3,536
  • 5
  • 45
  • 85
  • From your posted answer, I noticed that your issue has already been resolved. From your posted answer, I think that my answer was not useful. So, I would like to delete it because I don't want to confuse other users. I apologize for my poor skill. – Tanaike Mar 04 '23 at 00:18
  • You are very helpful sir. From your repository I've learned much. – shenkwen Mar 04 '23 at 13:53

1 Answers1

0

I've found the cause. It is on https://developers.google.com/apps-script/guides/web

{
  "queryString": "username=jsmith&age=21",
  "parameter": {
    "username": "jsmith",
    "age": "21"
  },
  "contextPath": "",
  "parameters": {
    "username": [
      "jsmith"
    ],
    "age": [
      "21"
    ]
  },
  "contentLength": -1
}

So, e.parameter and e.parameters are different. In my original code I used e.parameters. After changing it to e.parameter everything works fine.

P.S. If you do .appendRow([2],[3]), the values put into the sheet will also be something like [Ljava.lang.Object;@6cb45dd3 [Ljava.lang.Object;@53ea3fe8. Hope someone can explain a little about this.

shenkwen
  • 3,536
  • 5
  • 45
  • 85