Skip to content

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-KEY header 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 sends bundleType, count, manufacturerId, manufacturerName in 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 to URL_CREATE_BUNDLE.
  • openPopulateDocsDialog() — Opens a modal dialog to collect bundleType, count and optional manufacturer from 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 to URL_POPULATE_DOCS with X-API-KEY header.

n8n workflow recommendations

  • Use the Webhook node configured to accept POST requests. Validate the X-API-KEY header 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_BUNDLE and TOKEN_POPULATE_DOCS with 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 curl or Postman using the examples above. Verify the X-API-KEY header is accepted by the n8n Webhook node.
  • Check Google Apps Script executions (Apps Script dashboard) for failures and console.log output.
  • 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_DOCS in app_scripts/n8n Webhook Bundles.gs.
  • Script location (repo): app_scripts/n8n Webhook Bundles.gs