n8n Bundles Webhook (Google Apps Script integration)¶
This page documents the Google Apps Script located at app_scripts/n8n Webhook Bundles.gs which triggers two n8n webhooks used by the team:
- Create Bundles webhook — a lightweight trigger used to start the bundling flow.
- Populate Docs webhook — accepts bundle parameters (type, count, manufacturer) and triggers a workflow that populates documents via n8n.
Location
- Script:
app_scripts/n8n Webhook Bundles.gs(in the repository root)
How it works
- The script exposes a small UI in Google Sheets (menu "⚙️ Automation") and contains functions that POST JSON payloads to configurable n8n webhook URLs. The script uses an
X-API-KEYheader for simple token-based authentication. - Two webhook endpoints are used by the script (configured as constants at the top of the script):
URL_CREATE_BUNDLE+TOKEN_CREATE_BUNDLE— triggers the bundling workflow.URL_POPULATE_DOCS+TOKEN_POPULATE_DOCS— triggers the populate-docs workflow and sendsbundleType,count,manufacturerId,manufacturerNamein the payload.
Payload examples
- Create bundle (minimal):
{ "status": "triggered" }
- Populate docs (detailed):
{
"bundleType": "Value Pack",
"count": 3,
"manufacturerId": "3",
"manufacturerName": "Rituals",
"status": "populate_docs_triggered"
}
Curl examples (replace URLs/tokens with your environment)
Create bundle:
curl -X POST "https://n8n.example.com/webhook/CREATE_UUID" \
-H "X-API-KEY: YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"status":"triggered"}'
Populate docs:
curl -X POST "https://n8n.example.com/webhook/POPULATE_UUID" \
-H "X-API-KEY: YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"bundleType":"Value Pack","count":2,"manufacturerId":"3","manufacturerName":"Rituals","status":"populate_docs_triggered"}'
Google Apps Script functions (summary)
onOpen()— Adds the "⚙️ Automation" menu to the Google Sheet.triggerN8nWebhook()— Sends the minimal create-bundle payload toURL_CREATE_BUNDLE.openPopulateDocsDialog()— Opens a modal dialog to collectbundleType,countand optionalmanufacturerfrom the user.executePopulateDocsWorkflow(bundleType, count, manufacturerId, manufacturerName)— Client-side bridge that validates input and calls the server-side sender.sendPopulateDocsToN8n(bundleType, count, manufacturerId, manufacturerName)— Builds the JSON payload and POSTs it toURL_POPULATE_DOCSwithX-API-KEYheader.
n8n workflow recommendations
- Use the Webhook node configured to accept POST requests. Validate the
X-API-KEYheader early in the flow (use an If/Function node or a simple header check). Do not rely on secret tokens being sent in query strings. - Recommended flow (Populate Docs): Webhook → Validate header → JSON Parse → (optional) Lookup manufacturer by id → Document generation / sheet population → Notify user (Slack/Discord/email) → Mark run result in DB/log.
- Recommended flow (Create Bundles): Webhook → Validate header → Trigger bundling worker → Return 202 accepted and log run id.
Security and best practices
- Do not commit real tokens to the repository. Replace
TOKEN_CREATE_BUNDLEandTOKEN_POPULATE_DOCSwith environment-managed secrets if possible. - Use long random tokens and rotate them periodically.
- Restrict the webhook host or protect it via n8n authentication. Consider IP allowlisting if n8n is reachable only from internal networks.
Testing & troubleshooting
- Test the webhook with
curlor Postman using the examples above. Verify theX-API-KEYheader is accepted by the n8n Webhook node. - Check Google Apps Script executions (Apps Script dashboard) for failures and
console.logoutput. - Check n8n execution logs for received payloads and errors.
Appendix — Where to edit
- Edit constants in the script:
URL_CREATE_BUNDLE,TOKEN_CREATE_BUNDLE,URL_POPULATE_DOCS,TOKEN_POPULATE_DOCSinapp_scripts/n8n Webhook Bundles.gs. - Script location (repo):
app_scripts/n8n Webhook Bundles.gs