These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

JSON Google Script

Author
Jekira Nu
Perkone
Caldari State
#1 - 2014-07-24 22:32:06 UTC
I'm trying to write a script to acquire JSON data from EVE-MarketData and have it on my Google Sheet.

My point that I'm trying to access is : [url]http://api.eve-marketdata.com/api/item_prices2.json?char_name=demo&type_ids=34&station_ids=60003760&buysell=s[/url]

And I've been trying this :

Quote:

function simplejita(item)
{
var jsondata = UrlFetchApp.fetch("http://api.eve-marketdata.com/api/item_prices2.json?char_name=demo&buysell=s&station_ids=60003760&type_ids="+item);

var object = Utilities.jsonParse(jsondata.getContentText());

return object.emd.result.row.price;
}


All I want to do is pass in the item_id and get out the price. I can't seem to get anything out of it, either it is an error or a blank cell.
salacious necrosis
Garoun Investment Bank
Gallente Federation
#2 - 2014-07-25 06:13:38 UTC
object.emd.result is an array which you need to index. Example:

http://api.eve-marketdata.com/api/item_prices2.json?char_name=demo&buysell=s&station_ids=60003760&type_ids=5

gives the JSON response:

{
"emd": {
"version": 2,
"currentTime": "2014-07-25T5:22:21Z",
"name": "item_prices",
"key": "buysell,typeID,stationID",
"columns": "buysell,typeID,stationID,price,updated",
"result": [{
"row": {
"buysell": "s",
"stationID": "60003760",
"typeID": "5",
"price": "0",
"updated": "2014-07-25 5:22:21"
}
}]
}
}

so you want object.emd.result[0].row.price

Also, note that Utilities.jsonParse was deprecated. You'll want to use JSON.parse instead.

Use EveKit ! - Tools for EVE Online 3rd party development

Jekira Nu
Perkone
Caldari State
#3 - 2014-07-25 11:08:33 UTC  |  Edited by: Jekira Nu
Excellent!

Thanks salacious.

Script works great, now I run into an issue with too many calls. I tried to JOIN a range of cells and send it an array of data but it doesn't like that. Though for those who would like to try it for smaller sheets, here it is.

function stationsell(item_id,stationid)
{
var jsondata = UrlFetchApp.fetch("http://api.eve-marketdata.com/api/item_prices2.json?char_name=demo&type_ids="+item_id+"&station_ids="+stationid+"&buysell=s&minnmax=min");
var object = JSON.parse(jsondata);
Utilities.sleep(1000)
return object.emd.result[0].row.price;
}
Wafflehead
Garoun Investment Bank
Gallente Federation
#4 - 2014-07-25 11:58:47 UTC
Move away from spreadsheets or use PHP or create a proper application (.Net, C#, VB.Net) etc.
Jekira Nu
Perkone
Caldari State
#5 - 2014-07-25 12:05:58 UTC
I think that's the direction I'll have to move. I've definitely pushed what Google Sheets is capable of. The crunch times are getting too long.