🧾 Issue sequential invoice and ticket numbers via webhook and Data Table
⚡ 1 views · 🧾 Invoice Processing
Description
Quick Overview
This workflow exposes a POST webhook that issues the next gapless sequential number (for invoices, tickets, or other sequences) by reading and updating a counter stored in an n8n Data Table, and returns a formatted number with an optional prefix and zero padding.
How it works
- Receives a POST request on a webhook endpoint with a
sequence_keyand optionalprefixandpadparameters. - Validates and normalizes the request values, falling back to safe defaults if inputs are missing or malformed.
- Looks up the matching counter row in the n8n Data Table
number_sequencesusing the providedsequence_key. - Calculates the next counter value, applies the requested or stored prefix, and formats the number using the requested zero-padding width.
- Upserts the updated counter back into the
number_sequencesData Table keyed bysequence_key. - Returns a JSON response containing the issued formatted number, the updated counter value, and a timestamp.
Setup
- Create an n8n Data Table named
number_sequenceswith columnssequence_key(string),current_value(number),prefix(string), andupdated_at(string). - Ensure the Data Table name/reference in the read and upsert steps points to
number_sequencesand thatsequence_keyis used as the matching column. - Activate the workflow, copy the production webhook URL for
/next-number, and configure your calling system to POST a JSON body such as{ "sequence_key": "invoice", "prefix": "INV-", "pad": 6 }. - If you require strictly no gaps, serialize requests to this endpoint (for example, by ensuring a single caller or limiting concurrent executions) to avoid simultaneous reads of the same counter value.
🔗 Nodes Used
Webhook, Data table
📥 Import
Download workflow.json and import into n8n:
Workflow menu → Import from File