Every 15 minutes
Save supplier attachments to S3 and log their details in a sheet
Attachments from your suppliers' emails are saved to S3, and the invoice number, date and total from each one are added to your sheet with a link to the file.
- Runs
- Every 15 minutes
- Apps
- AWS, Google Sheets
- AI
- Yes, uses the built-in AI allowance
- Access
- s3:PutObject; Sheets write
Send this to your assistant
Create a ClickRuntime automation: every 15 minutes, take attachments from new emails from my suppliers, upload them to S3, extract invoice number, date and total with AI, and add a row to my Documents sheet.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
Supplier documents arrive by email and live there: invoices, delivery notes, certificates. When the accountant or an auditor asks for last March's invoices, someone spends an hour searching inboxes and forwarding attachments.
Saving each attachment to S3 as it arrives, with its key details in a sheet, gives you a single searchable register of supplier documents with a link to every file.
What you get out of it
Every document in one place
Attachments are stored together in your bucket, not scattered across personal inboxes.
Find anything in seconds
The sheet lets you filter by supplier, date or amount and open the file from the row.
Ready for your accountant
Handing over a quarter's invoices means sharing a filtered sheet, not forwarding emails.
Safe from inbox clean-ups
Files survive even if the original email is deleted.
How it works
What happens, step by step
Every 15 minutes, ClickRuntime checks Gmail for new emails with attachments from your suppliers.
It saves each attachment to your S3 bucket in a folder for the month and sender.
AI reads the email and picks out the invoice number, date and total.
It adds a row to your Documents sheet with those details and the file's S3 path.
Emails already handled are remembered, so files aren't saved twice.
Before it runs live
- Connect AWS
- Connect your Google Sheets account and pick the spreadsheets it may use
What you get
Build your own
Need it to work differently?
Your own rules
Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.
Any number of apps
One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.
AI where it helps
Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.
On a schedule or on each event
Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.
Changes you can ask for
- Act only on the items that match your own rules, and skip the rest
- Change what the AI looks for, or how it writes the result
- Add another app, for example also send it to Slack
- Combine it with other AWS and Google Sheets steps into one automation
Under the hood
The code that runs this automation
import base64, boto3
from datetime import date
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_trigger, credentials, http, state, ai, report_fetched
SHEET_ID = "your-spreadsheet-id"
QUERY = "has:attachment from:(@northwind.com OR @acme-supply.com) newer_than:2d"
REGION, BUCKET = "us-east-1", "northwind-files"
def aws(service):
return boto3.client(service, region_name=REGION, aws_access_key_id=credentials.secret("AWS_ACCESS_KEY_ID"),
aws_secret_access_key=credentials.secret("AWS_SECRET_ACCESS_KEY"))
@on_trigger
def run(event):
gmail, done = build("gmail", "v1", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False), set(state.get("done") or [])
msgs = [m for m in gmail.users().messages().list(userId="me", q=QUERY).execute().get("messages", []) if m["id"] not in done]
report_fetched(len(msgs))
if not msgs:
return {"summary": "Nothing new"}
s3, rows = aws("s3"), []
for m in msgs:
full = gmail.users().messages().get(userId="me", id=m["id"]).execute()
sender = next(h["value"] for h in full["payload"]["headers"] if h["name"] == "From").split("@")[-1].strip(">")
f = ai.generate(f"Return invoice number, date (YYYY-MM-DD) and total from:\n{full['snippet']}", max_output_tokens=80, json_schema={"type": "object",
"properties": {"number": {"type": "string"}, "date": {"type": "string"}, "total": {"type": "number"}}}).json
for p in [p for p in full["payload"].get("parts", []) if p.get("filename")]:
data = gmail.users().messages().attachments().get(userId="me", messageId=m["id"], id=p["body"]["attachmentId"]).execute()["data"]
key = f"{date.today():%Y/%m}/{sender}/{m['id']}-{p['filename']}"
s3.put_object(Bucket=BUCKET, Key=key, Body=base64.urlsafe_b64decode(data))
rows.append([sender, p["filename"], f.get("number"), f.get("date"), f.get("total"), f"s3://{BUCKET}/{key}"])
done.add(m["id"])
build("sheets", "v4", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False).spreadsheets().values().append(spreadsheetId=SHEET_ID, range="Documents!A:F", valueInputOption="RAW", body={"values": rows}).execute()
state.set("done", list(done)[-1000:])
return {"emails": len(msgs), "files": len(rows)}FAQ
Common questions
Which emails are included?
What if a document isn't an invoice?
How are files organised in S3?
What permissions does it need?
Does it need AI?
How many runs does it use?
Can I change how it works?
Related
You might also like
Transcribe audio uploaded to S3 into a Google Sheet
Every audio file you upload to your S3 bucket is transcribed, and the file name and transcript are added as a row in your sheet.
See how it worksArchive the pages in your sheet to S3 every month
On the 1st of each month, every page listed in your sheet is saved to S3 under that month's date, and the archive path is written back next to it.
See how it worksLabel new emails automatically
New mail is sorted into labels like Inquiry, Invoice and Newsletter within minutes of arriving.
See how it worksKeep exploring
Set up “Save supplier attachments to S3 and log their details in a sheet” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.