Push approved Timesheet Portal invoices into Xero each evening

By General Input

Every weekday evening, newly approved invoices move from Timesheet Portal into Xero on their own, so finance never rekeys another one.

Integrations

  • Timesheet Portal
  • Xero
  • Slack Bot

Type

Deterministic Code

Categories

  • Finance
  • Operations

Every weekday at 7pm, push newly approved Timesheet Portal invoices into Xero as sales invoices, so finance stops rekeying them. Use a cron trigger, because Timesheet Portal does not send outgoing webhooks and is not available as a poll source.

Start in Timesheet Portal with List Invoices, filtered to invoices that have not yet been marked as exported. If nothing comes back, end the run without posting anything so the Slack channel stays quiet on days with no new invoices.

Pull the line level detail with Get Invoice Report V2. Timesheet Portal caps its invoice report endpoints at 24 requests per hour, so make exactly one report call per run covering every invoice in the batch, rather than one call per invoice. Group the returned rows by invoice so each invoice has its own set of lines carrying the description, hours, rate and amount.

Before creating anything, call Xero List Invoices filtered to the Timesheet Portal invoice number and check whether an invoice with that number already exists. If it does, skip that invoice and count it as already synced. This check is what makes a rerun safe, so it must happen for every invoice before any write.

For each remaining invoice, call Xero Create Invoices to raise an accounts receivable sales invoice. Identify the contact by name using the Timesheet Portal client name, since there is no contact lookup operation in the catalog to resolve it first. Carry the Timesheet Portal invoice number into the Xero invoice number field, carry the invoice date and the due date, and create one Xero line item per Timesheet Portal line with the description, the hours as the quantity, the rate as the unit amount and the line amount. Create the invoice in draft status so finance can review before it goes out.

Only once Xero has confirmed the invoice, call Mark Invoices as Exported in Timesheet Portal for that invoice, so the same invoice is never picked up twice. Timesheet Portal upserts can return HTTP 200 with success set to false, so check the success flag in the response body rather than the status code before treating the mark as done. Never mark an invoice as exported when the Xero create failed.

Handle each invoice independently. If one invoice fails at any step, record its invoice number and the reason, leave it unmarked so the next run retries it, and carry on with the rest of the batch.

Finish by posting a run summary to a finance channel in Slack with Send a Message. Include the number of invoices synced, the total value synced, the number skipped because they were already in Xero, and one line for each invoice that failed showing its invoice number and the reason.

Related prompts

Explore more prompts
Call overdue Xero customers with an AI collections agentA brand asset library your marketing team actually searchesTurn Mailjet email clicks into ranked HubSpot follow-upsClean out the Looker dashboards and Looks nobody opensLiveKit live operations console for room moderationWake up dormant Keap leads with a researched reasonLiveChat coverage board for planning next week's shiftsPhone routing control panel for LiveKit voice agentsLinkedIn Ads budget pacing dashboard for every client accountGive your team Looker numbers without buying more seats