All jobs

Turn Each Cleaning Company's OneDrive Timesheets Into Payroll Hours: One Agent per Customer

Payroll software for cleaning companies makes one agent per customer that reads that week's crew timesheets from the owner's OneDrive and returns hours to approve.

Run this on RushOpens the console with this prompt ready to send. Connect OneDrive there first.

What the agent does

This is for a company that sells payroll software to residential and office cleaning companies. Most of its customers run crews of five to forty cleaners, and many still keep time the way they started: each crew lead fills in an Excel timesheet for the week and saves it to a folder in the owner's OneDrive, such as Timesheets/2026-11-10. Every Friday the owner opens each workbook, adds up hours by cleaner and types them into payroll. The software adds an Import from OneDrive button that does that reading for them, and leaves the approving to the owner.

The software saves the agent once as a template with POST /o/{org}/agents, naming "connections": ["onedrive"] (its own OneDrive is connected first, because a template names connections its creator has) and instructions that keep it to reading. When a customer turns the import on, its backend calls POST /o/{org}/agents {"template": "<template id>", "name": "timesheets-<customer id>"}, then POST /o/{org}/agents/{agent}/connections {"type": "app", "name": "onedrive"}, and opens the authorize_url in a popup while the owner is signed in to the software. The owner signs in on Microsoft's own page, so the software registers no Microsoft app and stores no Microsoft token, only the agent id against its customer.

A run reaches Microsoft Graph files as that owner. It lists the week's folder with GET /me/drive/root:/Timesheets/2026-11-10:/children and downloads each .xlsx with GET /me/drive/items/{id}/content, then reads the workbook inside the run's own computer. It does not use Graph's workbook endpoints: Microsoft documents usedRange and the other workbook calls for work or school accounts only, and some cleaning-company owners sign in with a personal Microsoft account. Each sheet is one crew, with a row per cleaner per shift: date, client or address, start, end and unpaid break.

The agent works out each shift's hours, totals them per cleaner for the week, and marks what an owner would want to see before paying: a shift whose end is before its start, two shifts for one cleaner that overlap, a day with a start and no end, a cleaner on more than one crew sheet, and anyone over the weekly hours the owner set in the software, which the backend passes in input. It returns hours.csv (cleaner, date, client, start, end, break, hours, flag) and totals.csv (cleaner, total hours, shifts, flags). It writes nothing back to OneDrive.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "<agent id>",
  "input": "Total this week's cleaning crew timesheets for payroll. Week: Monday 2026-11-10 to Sunday 2026-11-16. Use the OneDrive connection, Microsoft Graph files, reads only. 1) List GET /me/drive/root:/Timesheets/2026-11-10:/children. 2) Download every .xlsx file with GET /me/drive/items/{id}/content and read it locally; each sheet is one crew, header row Date, Cleaner, Client, Start, End, Break (minutes). 3) For each row compute hours = End - Start - Break. Flag: End before Start, a row with Start and no End, two rows for the same cleaner whose times overlap, a date outside the week, and the same cleaner on more than one sheet on one day. 4) Total hours per cleaner; flag anyone over 40 hours, the owner's setting. Write hours.csv (file, sheet, date, cleaner, client, start, end, break, hours, flag) and totals.csv (cleaner, total hours, shifts, flags), and a short summary of files read and any file you could not read. Do not upload, move, rename, delete or edit any file in OneDrive."
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

The session returns hours.csv and totals.csv as artifacts, and its answer lists the workbooks it read and any it could not open. The software's webhook handler loads totals.csv into a draft pay run for that customer, with every flagged row shown above the totals, so the owner sees the problems before the numbers.

What the owner checks before approving: each flagged shift against what the crew lead remembers, since a missing end time is usually a typo and not unpaid work; that a cleaner on two crews on one day really did both jobs; and anyone over their weekly hours setting, which is the owner's own number and decides nothing about overtime by itself. The run reads hours and adds them up. Pay rates, overtime rules and approval stay in the payroll software and with the owner.

Run it on every Friday, per customer

The software's scheduler sends one POST /o/{org}/sessions per customer with the import on, at noon on Friday in that customer's time zone, with that customer's agent id as agent, the week's folder and their hours setting in input, and a request_id that is a UUID v5 of the customer id and the week's Monday, so a retried job starts no second run. Runs past the key's max_concurrent wait as queued until a slot frees, and the key's webhook delivers each run.completed.

An owner who fixes a timesheet after the import presses Import again; the software starts a new run for the same week with a fresh request_id, and the draft pay run is replaced.

The use case this job follows, with its automation and trigger: Run an agent per customer task.

Why run it on Rush?

Each owner's Microsoft sign-in belongs to that owner's agent, connected at /o/{org}/agents/{agent}/connections. The software never holds a Microsoft token, and a run of one cleaning company's agent cannot reach another company's files. Every session lists the account it used in accounts, so the software can show an owner when their OneDrive was read and by which run.

Rush's OneDrive app asks Microsoft for Files.ReadWrite.All, more than this job needs, and Gmail and Outlook are the only apps a template can narrow. The template's instructions forbid writing, each run has its own computer, and its record lists every Graph call it made, which is what the software shows a customer who asks what the import did.

Frequently asked questions

Does this work with a personal Microsoft account?

Yes. The run downloads each workbook's file and reads it itself, and listing a folder and downloading a file work for personal and work accounts alike. Graph's workbook calls such as usedRange are documented for work or school accounts only, which is why the run does not use them.

What if a crew lead names a column differently?

The agent reports any sheet whose header row does not match, with the file name, rather than guessing which column holds the end time. The software can then show the owner which sheet to fix.

Does the agent work out overtime pay?

No. It flags anyone over the weekly hours the owner set and passes the hours to the payroll software. How overtime is paid depends on the owner's rules and where they operate, and stays with them.

What does the software store about each customer?

Only the agent id against the customer. Rush stores and refreshes the Microsoft sign-in under that agent, and deleting the agent disconnects it.

More OneDrive jobs

The same job in other apps

More jobs like this: Run an agent per customer task

Keep reading