Custom Function to create invoices from Desk's TimeEntry

Custom Function to create invoices from Desk's TimeEntry

I need to develop a custom function that takes the total time spent by our agents and turns it into an invoice

I started with this:

orgId = xxxxxx;
response = zoho.desk.getRecords(orgId, "agents");
agentes = response.getJson("data"); 
rec = agentes.toJsonList();
agentesList = List();
for each agente in rec 
{
agentesList.add(agente.getJson("id"));
}
info agentesList;