Home > front end >  Script to fetch events/ID/name from an API, then list them, G-sheet
Script to fetch events/ID/name from an API, then list them, G-sheet

Time:08-17

Guilded just (pre)released an API, and I wish to use it to retrieve the list of events, events's id, events's names from my server, and have it in a Google-sheet. Next, I'll try to retrieve the members from the events. I had a similar issue yesterday for the server's members, but I don't seem to understand how to read the data I'm pulling -_-'

I have a test file here : https://docs.google.com/spreadsheets/d/1ZUZ6utQO6cW_BAy6cMACxX2H1_zrZAIE0CTtTmdN9nc/edit?usp=sharing

​Thank you for any help you could provide,

Nyl,

CodePudding user response:

When I saw your sample Spreadsheet, I found your current script. When your current script is modified, how about the following modification?

From:

let id = [];

for (var i = 0; i < data.id.length; i  ){
  
  name.push([data.id[0],data.id[0].name,data.id[i].startsAt]);
}

ss.getActiveSheet().getRange(10,4,id.length,2).setValues(id);

To:

var values = data.calendarEvents.map(({ id, name, startsAt }) => [id, name, startsAt]);
ss.getActiveSheet().getRange(10, 4, values.length, values[0].length).setValues(values);

Reference:

  • Related