How to Integrate the Google sheets via ERPNext Rest API


We are trying to get data of ERPNext using rest API into the Google Sheet. We are getting the request but when we try to get data by using the method getContentText(), getting an error like below TypeError: Cannot read property ‘getContentText’ of undefined

function myFunction() {

var request = {

‘url’ : ‘'+encodeURIComponent('filters=[["Item", "commercial_name", "like", "Mars 200"]]’),

‘method’ : ‘get’,

‘escaping’ : false,

‘muteHttpExceptions’: true,

‘contentType’: ‘application/json’,



    'Authorization': "token "+ "xxxxxxxxxxxxxxx" + ":" + "xxxxxxxxxxxxxxx",

    'Accept': 'application/json' 



var response = UrlFetchApp.fetchAll([request]);


var jsontype = typeof(response);

var json1 = JSON.parse(response);

var jsontype1 = typeof(json1);

var jsonresponse = response;

for (var c = 0; c < response[0].length; c++) {






var sheet = SpreadsheetApp.getActiveSheet();



It should be Logger.log(response.getContentText()); instead of Logger.log(jsonresponse.getContentText()); you are using a variable in line 18 that are defined in line 22.

BTW, This is not an ERPNext related question.

Hi @froldan,

Even after the change did like what you said facing the same issue,

Hi, please refer to the documentation or make a query in a forum related to Google Apps Script.