add_google_sheets_row
Append a row to a Google Sheet.
add_google_sheets_row(sheet_id: str, data: dict) -> dictAdds a row to a Google Sheet. Each key in the data dict maps to a column header, and the value becomes the cell content.
Parameters
| Name | Type | Description |
|---|---|---|
sheet_id | str | The spreadsheet ID — the part of the Google Sheets URL between /d/ and /edit |
data | dict | Column-value pairs. Keys are column headers, values are cell contents. All values are converted to strings |
Returns
dict — {"success": bool, "message": str}
Prerequisites
The Google Sheet must be shared with the Octocom service account:
Give it Editor access. The sheet must have a header row — column names in the first row that match the keys in your data dict.
Examples
Log refund events to a spreadsheet
def execute_action(context):
order_id = context["args"]["orderId"]
amount = process_refund(order_id)
add_google_sheets_row("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms", {
"Order ID": order_id,
"Refund Amount": amount,
"Reason": context["args"].get("reason", ""),
"Date": datetime.now().isoformat(),
"Conversation ID": context["conversation"]["id"],
})
return {"success": True, "amount": amount}Collect lead information
def execute_action(context):
add_google_sheets_row("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms", {
"Name": context["args"]["name"],
"Email": context["args"]["email"],
"Company": context["args"]["company"],
"Interest": context["args"]["interest"],
})
return {"success": True, "message": "Thank you, we'll be in touch!"}