I have this array that I'm pulling from Pipedrive using API: [John Smith, [555-867-5309, 444-867-5309], [john@gmail.com, john@yahoo.com]] I want this array to populate to the Google sheet like so:
| A | B | C |
=========+========+========+========+========+========+========+========+========+===============
1 | John Smith | 555-867-5309, 444-867-5309 | john@gmail.com, john@yahoo.com |
I'm using setValues but am getting an error that the number[] doesn't match the method signature for range.setValues so it's not pasting anything to the sheet.
Here's my code. It works to pull in the data. I just want to pull the three fields (name, phone, and email) of all the data it returns.
var URL = "https://....pipedrive.com";
var API_TOKEN = "...";
function test() {
var sheeturl = 'https://docs.google.com/spreadsheets/d/...';
var ss = SpreadsheetApp.openByUrl(sheeturl);
var leadsSheet = ss.getSheetByName('Leads Sheet');
var personData = [];
var personurl = URL +'/v1/persons/3812?api_token='+ API_TOKEN;
var options = {
"method": "get",
"contentType": "application/json",
};
var response = UrlFetchApp.fetch(personurl, options);
response = JSON.parse(response.getContentText());
var name = response.data.name;
var phone = [response.data.phone.map(phone => phone.value).join(', ')];
var email = [response.data.email.map(email => email.value).join(', ')];
var personArray = [name, phone, email];
Logger.log(personArray);
personData.push(personArray);
leadsSheet.getRange(leadsSheet.getLastRow()+1, 5, personData.length, personData[0].length).setValues(personData); //writes to end of sheet
}
The log from this is: [20-10-25 16:29:34:339 EDT] [John Smith, [555-867-5309, 444-867-5309], [john@gmail.com, john@yahoo.com]]
but nothing populates to the sheet; it remains blank.