function doPost(e) {
var postdatacontents = JSON.parse(e.postData.contents)
var ss = SpreadsheetApp.openByUrl('INSERT YOUR SHEET URL HERE')
var sheetarray = ss.getSheets();
var sheetnum = 0;
//This code will display inventory items on sheets named after your characters. The syntax is Character Name@Server. You must create the initial sheets and name them appropriately.
for (var x = 0; x < sheetarray.length; x++) {
if (sheetarray[x].getName() == postdatacontents.char_info)
sheetnum = x;
}
var sheet = ss.getSheets()[sheetnum];
//This code will display inventory items on sheets named after your characters. The syntax is Character Name@Server. You must create the initial sheets and name them appropriately.
sheet.clear();
sheet.getRange(1,1).setValue('Name');
sheet.getRange(1,2).setValue('Quantity');
sheet.getRange(1,3).setValue('Total Quantity');
var numOfInventoryItems = postdatacontents.inventory.length;
var itemnametocheck = new Object();
var itemindices = new Object();
for (var c = 0; c < numOfInventoryItems; c++)
{
sheet.getRange(c+2, 1).setValue(postdatacontents.inventory[c].name);
sheet.getRange(c+2, 2).setValue(postdatacontents.inventory[c].quantity);
if (itemnametocheck.hasOwnProperty(postdatacontents.inventory[c].name) == false)
{
itemnametocheck[postdatacontents.inventory[c].name] = postdatacontents.inventory[c].quantity;
itemindices[postdatacontents.inventory[c].name] = c+2;
}
else
{
itemnametocheck[postdatacontents.inventory[c].name] += postdatacontents.inventory[c].quantity;
}
}
//This code displays the total quantity for a particular item at the index of the first occurance of that item
for (const [n, q] of Object.entries(itemnametocheck)) {
sheet.getRange(itemindices[n],3).setValue(q);
}
//This code displays the total quantity for a particular item at the index of the first occurance of that item
sheet.getRange(142, 1).setValue("Gil:");
sheet.getRange(142, 2).setValue(postdatacontents.gil);
//This code will display Buy List items on sheets named after FFXIV's servers. You must create the initial sheets and name them appropriately.
sheetnum = 0;
for (var x = 0; x < sheetarray.length; x++) {
if (sheetarray[x].getName() == postdatacontents.server)
sheetnum = x;
}
sheet = ss.getSheets()[sheetnum];
//This code will display Buy List items on sheets named after FFXIV's servers. You must create the initial sheets and name them appropriately.
sheet.clear();
sheet.getRange(1, 1).setValue("Market Board Item");
sheet.getRange(1, 2).setValue("Price");
var numOfMBItems = postdatacontents.mb_prices.length;
for (var c = 0; c < numOfMBItems; c++)
{
sheet.getRange(c+2, 1).setValue(postdatacontents.mb_prices[c].name);
sheet.getRange(c+2, 2).setValue(postdatacontents.mb_prices[c].price);
}
return ContentService.createTextOutput('Success');
}