0

I'm trying to connect a smartsheet table to Googlesheets using apps script. I'm able to connect to the smartsheet but pulling the data based on the field names isn't working.

function getSpeakers() {
  var speakers = requestsmartsheet();
  //console.log("speakers: ", speakers)
  var speaker_info = [];

  //Here is where I'm having trouble with the field names. Field names are the exact names from the table
  for(i=0; i<speakers.length; i++) {
    var fields = speakers[i].fields;
    speaker_info.push([
      fields.FirstName,
      fields.LastName,
      fields.Email,
      fields.E-Number
    ])
  }
  console.log("speaker_info: ", speaker_info);
}

function requestsmartsheet() {
  var url = "https://api.smartsheet.com/2.0/sheets/[link ID]"
  var headers = {
    "Authorization": "Bearer [token]",
    "Content-Type": "application/json"
  }
  var options = {
    headers: headers,
    method: "GET"
  }

  var response = UrlFetchApp.fetch(url, options);
  var result = JSON.parse(response);
  //console.log("result: ", result)

  return result.records
}
Rubén
  • 34,714
  • 9
  • 70
  • 166

1 Answers1

1

Try replacing fields.E-Number by fields.['E-Number']. If that doesn't work, use the debugger or add console.log(JSON.stringify(speakers, null, ' ') after var speakers = requestsmartsheet(); to review the records property that your script is receiving.

You might also spend some time reviewing the Smartsheet API docs.

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • So it's running but the execute log is just showing Execution log 7:52:04 PM Notice Execution started 7:52:05 PM Notice Execution completed Nothing is actually being pulled. – Allister Lobo Sep 08 '22 at 01:53
  • If you are looking the execution logs on the execution page, click the entre to expand it – Rubén Sep 08 '22 at 02:14