@NG1808
I don’t think there is a trigger that will allow you to do this. You may be able to use an on update but that would be chunky and require user intervention.
You may have some luck using Xero’s API GET INVOICES
https://developer.xero.com/documentation/api/accounting/invoices/#get-invoices
This would require you to use some code and have access tokens etc. It may be possible to do this within a python code block with requests where you ask for invoices where the due date is over 14 days old. The JSON response could then be handled by additional steps.
I do feel it would be quite a sophisticated piece of programming although ChatGPT has provided me with the outline of how to do it (see code below)
Another option that just occurred to me is that you could have a workaround from a table/spreadsheet where the invoice and due date are identified and you populate this on a new invoice trigger.
When an invoice is paid you could remove them from the sheet or mark as paid.
Then check this sheet with a daily or weekly trigger to find unpaid invoices over 14 days from the due date and then send your slack messages.
It’s a workaround that would meant no API coding required although it would mean having to have an additional table/spreadsheet of financial data outside of Xero. You could keep this table/spreadsheet reasonably anonymous by using Invoice numbers and dates.
It will be easier to implement although likely to be a series of Zaps.
Hope this helps.
import requests
import json
# Replace these values
ACCESS_TOKEN = "your_xero_access_token"
ORGANIZATION_ID = "your_organization_id"
# Xero API endpoint to fetch invoices
url = "https://api.xero.com/api.xro/2.0/Invoices"
# Headers with Authorization and Content-Type
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Accept": "application/json"
}
# Query Parameters to filter for invoices 14 days past due date
params = {
"where": "Status==\"AUTHORISED\"&&DueDate<DateTime.UtcNow().AddDays(-14)"
}
# Make the GET request to the Xero API
response = requests.get(url, headers=headers, params=params)
# Process the response
if response.status_code == 200:
invoices = response.json().get("Invoices", o])
overdue_invoices =
{
"InvoiceNumber": inv "InvoiceNumber"],
"ContactName": inv "Contact"]N"Name"],
"DueDate": inv "DueDate"],
"AmountDue": inv "AmountDue"]
}
for inv in invoices
]
output = json.dumps(overdue_invoices)
else:
output = f"Error: {response.status_code}, {response.text}"
return {"overdue_invoices": output}