n8n series · Google Sheets · webhook · email
n8n with Google Sheets: save form submissions and send automatic reports
Google Sheets is the database of many small businesses. With n8n you can write a row every time someone fills in a form on your site and read the sheet to send alerts or reports.
Quick answer
Create a Google OAuth credential in n8n and use the Google Sheets node with Append Row to write and Get Rows to read. Combine it with a Webhook for forms and a Schedule Trigger for reports.
1. Connect n8n with Google
- In Google Cloud Console create a project and enable the Google Sheets API and Google Drive API.
- Configure the OAuth consent screen and add your email as a test user.
- Create a Web application OAuth client and paste the redirect URI shown by n8n.
- In n8n: Credentials → Google Sheets OAuth2 API, paste the ID and secret and click Sign in with Google.
2. Save a web form into the sheet
Webhook (POST /contacto) → Code → IF ok → Google Sheets (Append Row) → Respond to Webhook
Create a sheet with the columns Fecha, Nombre, Email, Mensaje and Estado (rename them if you prefer English, and the keys in the code too).
// Code: valida y normaliza antes de escribir en la hoja
const b = $input.first().json.body ?? {};
const email = String(b.email ?? '').trim().toLowerCase();
if (!b.nombre || !/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) {
return [{ json: { ok: false, error: 'Nombre y email válidos son obligatorios' } }];
}
return [{
json: {
ok: true,
Fecha: new Date().toISOString().slice(0, 16).replace('T', ' '),
Nombre: String(b.nombre).trim().slice(0, 100),
Email: email,
Mensaje: String(b.mensaje ?? '').trim().slice(0, 1000),
Estado: 'Nuevo',
},
}];Test it from the terminal:
curl -s -X POST https://n8n.midominio.com/webhook/contacto \
-H 'Content-Type: application/json' \
-d '{"nombre":"Ana López","email":"ana@example.com","mensaje":"Quiero un presupuesto"}'3. Weekly email report
Schedule Trigger (Monday 8:00) → Google Sheets (Get Rows) → Code → Send Email
// Code: resumen semanal a partir de las filas leídas de Google Sheets
const filas = $input.all().map((i) => i.json);
const hace7 = Date.now() - 7 * 86400000;
const semana = filas.filter((f) => new Date(f.Fecha.replace(' ', 'T')).getTime() >= hace7);
const pendientes = filas.filter((f) => f.Estado === 'Nuevo');
return [{
json: {
asunto: `Resumen semanal: ${semana.length} contactos nuevos`,
texto: [
`Contactos esta semana: ${semana.length}`,
`Pendientes de responder: ${pendientes.length}`,
'',
...pendientes.slice(0, 20).map((f) => `- ${f.Nombre} <${f.Email}>: ${f.Mensaje.slice(0, 80)}`),
].join('\n'),
},
}];Frequently asked questions
Can I use a service account instead of OAuth?
Yes: create it in Google Cloud, add a Google Service Account credential in n8n and share the sheet with the service account email.
How do I update a row instead of adding one?
Use Update Row or Append or Update Row with a key column such as the email.