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 & retainer 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 & retainer 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();
var numOfRetainers = postdatacontents.retainers.length;
for (var c = 0; c < numOfRetainers; c++)
{
sheet.getRange(2, c * 6 + 1).setValue('Retainer ' + (c+1).toString());
sheet.getRange(2, c * 6 + 2).setValue('Quantity');
sheet.getRange(2, c * 6 + 3).setValue('Lowest Price');
sheet.getRange(2, c * 6 + 4).setValue('Price');
sheet.getRange(2, c * 6 + 5).setValue('Total Price');
sheet.getRange(2, c * 6 + 6).setValue('');
var numOfItems = postdatacontents.retainers[c].items.length;
for (var d = 0; d < numOfItems; d++)
{
sheet.getRange(d + 3, c * 6 + 1).setValue(postdatacontents.retainers[c].items[d].name);
sheet.getRange(d + 3, c * 6 + 2).setValue(postdatacontents.retainers[c].items[d].quantity);
sheet.getRange(d + 3, c * 6 + 3).setValue(postdatacontents.retainers[c].items[d].lowest_price);
sheet.getRange(d + 3, c * 6 + 4).setValue(postdatacontents.retainers[c].items[d].price);
var itemtotalprice = postdatacontents.retainers[c].items[d].price * postdatacontents.retainers[c].items[d].quantity;
sheet.getRange(d + 3, c * 6 + 5).setValue(itemtotalprice);
sheet.getRange(d + 3, c * 6 + 6).setValue('');
}
}
sheet.getRange(24,1).setValue('Inventory');
sheet.getRange(24,2).setValue('Quantity');
var numOfInventoryItems = postdatacontents.inventory.length;
for (var c = 0; c < numOfInventoryItems; c++)
{
sheet.getRange(c+25,1).setValue(postdatacontents.inventory[c].name);
sheet.getRange(c+25,2).setValue(postdatacontents.inventory[c].quantity);
}
return ContentService.createTextOutput('Success');
}