Can't Request Specific Node Info through Google Sheets

Hey all. I’m trying to update my Google Sheet tracker to pull the new data provided with the node monitoring tool. I wrote up the following script, which pulls all the data in just fine. But when I try to break it up into different cells, it returns nothing. What am I missing here?

function myMonitor() {
//GET PUBLIC VALIDATOR KEY

var sh=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“NODEINFO”);
**var rowNum = sh.getRange(‘F6’).getValue(); **

//POST NODE STATUS QUERY

** var url = “http://monitor.incognito.org/pubkeystat/stat”; **
** var data = { “mpk”: rowNum**
** };**


** var options = {**
** ‘method’ : ‘post’,**
** ‘contentType’: ‘application/json’,**
** ‘payload’ : JSON.stringify(data)**
** };**


** var response = UrlFetchApp.fetch(url, options);**
** var txt= response.getContentText();**
** var d=JSON.parse(txt);**

//RETURN RESULTS BACK TO GOOGLE SHEET

var sh1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“MONITOR”);

sh1.getRange(1, 1).setValue(d);
}

Result:

{Role=PENDING, AutoStake=true, SyncState=SHARD SYNCING, Alert=true, CommitteeChain=2, VoteStat=[Ljava.lang.Object;@1db148d2, NextEventMsg=12 epoch to be COMMITEE, Status=ONLINE, MiningPubkey=}

Now if I try the same thing, and switch the last line to:

sh1.getRange(1, 1).setValue(d.NextEventMsg);

it returns nothing. Any ideas?

1 Like

Whoa, Bro…very very awesome and cool your work so far on attempting to create this worksheet for pulling more info from the node monitoring tool…I am not familiar with coding practices so therefore I can’t assist you with this but hey big kudos to you for putting this thing together so far on your own…I imagine that someone will possibly assist you with completing your mini-project…best of luck…I will be keeping a close eye on this one and everyone should…this will be very helpful to all with Nodes…oh quick question is this for vNodes or pNodes or both?.. :100: :partying_face: :sunglasses:

This would work for both vnodes & pnodes

1 Like

Maybe you need to parse/stringify the JSON. Perhaps setValue isn’t able to do that on its own?

1 Like

It should? I mean, this is exactly how I’m doing it to pull public key data on all nodes currently. The only difference is this is a Post request instead of a Get request. So I feel like this should work…Is it possible for them to lock specific JSON pulls like that?

Is this what youre talking about @Josh_Hamon? I think I’m already doing what you are talking about

var options = {
‘method’ : ‘post’,
‘contentType’: ‘application/json’,
‘payload’ : JSON.stringify(data)
};

var response = UrlFetchApp.fetch(url, options);

1 Like

I’m thinking JSON.parse(d.BlaBlaBla) but I’m not near a computer to give it a try.

1 Like

I tried something like that, but it was giving me an undefined. I keep looking at my original code, and I feel like this is just some Monday detail Im missing.

1 Like

I said JSON.parse but I meant JSON.stringify(d.NextEventMsg). If Sheets is fickle, then you might need

var n = JSON.stringify(d.NextEventMsg);
sh1.getRange(1,1).setValue(n);

I updated it, but still a no go. The funny thing is the script execution completes your way and mine. It just doesn’t display any info.

var options = {
‘method’ : ‘post’,
‘contentType’: ‘application/json’,
‘payload’ : JSON.stringify(data)
};

var response = UrlFetchApp.fetch(url, options);
var txt= response.getContentText();
var d=JSON.parse(txt);
var n = JSON.stringify(d.NextEventMsg)
//RETURN RESULTS BACK TO GOOGLE SHEET

var sh1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“MONITOR”);

sh1.getRange(1,1).setValue(n);

@Josh_Hamon, I found the problem. The original way I did it was fine. I hit up some forums, and someone saw that the result is actually in an array. Needed d[0].

// header
sh.getRange(1, 1, 1, Object.keys(d[0]).length).setValues([Object.keys(d[0])]);
// contents
d.forEach(function (data, row){
  Object.keys(data).forEach(function (key, index){
    sh.getRange(row + 2, index + 1).setValue(data[key]);
  });
});

At least I dont feel as crazy lol.

2 Likes

So parse takes in the JSON and turns it into an array?

No, JSON data is already an array. To access the values within it, you need to add the index number. In this case, [0].