How to Integrate the Google sheets via ERPNext Rest API

Hi,

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’ : ‘https://pranera.erpnext.com/api/resource/Item/?limit_start=None&limit_page_length=None&parent=Item&’+encodeURIComponent('filters=[[“Item”, “commercial_name”, “like”, “Mars 200”]]’),

‘method’ : ‘get’,

‘escaping’ : false,

‘muteHttpExceptions’: true,

‘contentType’: ‘application/json’,

‘headers’:

{ 

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

    'Accept': 'application/json' 

}

};

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

Logger.log(jsonresponse.getContentText());

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++) {

Logger.log(response[c]);

}

Logger.log(jsontype);

Logger.log(jsontype1);

Logger.log(json1);

var sheet = SpreadsheetApp.getActiveSheet();

sheet.getRange(1,1).setValue([jsonresponse]);

}

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.