Fun with Scriptable and Fortnite

Two Fortnite scripts I created originally in Shortcuts, but the UITable display is what I was missing. Pretty rudimentary, I know but still fun.

Get the current challenges

let url = "https://api.fortnitetracker.com/v1/challenges";
let req = new Request(url);
// Free API key: https://fortnitetracker.com/site-api
req.headers = {"trn-api-key":"your-api-key"}
let json = await req.loadJSON()
// QuickLook.present(json)
let t = new UITable()
for(item of json.items) {
  var name = ""
  var total = ""
  var img = ""
  for(data of item.metadata){
    let k = data.key
    let v = data.value
    if (k == "name") {
      name = v
    } else if (k == "questsTotal" && v > 1) {
      total = v
    } else if (k == "rewardPictureUrl") {
      img = v
    }
  }
  let row = new UITableRow()
  let iCell = row.addImageAtURL(img)
  let nCell = row.addText(name, total)
  iCell.widthWeight = 10
  nCell.widthWeight = 90
  row.height = 80
  row.cellSpacing = 10
  t.addRow(row)
}
QuickLook.present(t)

Get what’s in the store now

let url = "https://api.fortnitetracker.com/v1/store";
let req = new Request(url);
// Free API key: https://fortnitetracker.com/site-api
req.headers = {"trn-api-key":"your-api-key"}
let json = await req.loadJSON()
let t = new UITable()
for(var i = 0; i < json.length; i++) {
  let o = json[i];
  let row = new UITableRow()
  let iCell = row.addImageAtURL(o.imageUrl)
  let nCell = row.addText(o.name, o.vBucks + " vBucks")
  iCell.leftAligned()
  iCell.widthWeight = 30
  nCell.widthWeight = 70
  row.height = 100
  row.cellSpacing = 10
  t.addRow(row)
}
QuickLook.present(t)

I’m working on the stats endpoint but it is really oddly implemented and not intuitive at all. I’ll post here if I get an update on it sometime, but definitely not at the top of my to do list.

4 Likes