← Back to blog

n8n lookup table: an exercise in gating API payloads

Build an n8n lookup table exercise that preserves duplicate mappings, checks codes and expiry, and routes proposed API payloads for review.

A sorting gate admits one key while paired keys, an hourglass and a broken key sit in trays.

Checked against the cited sources on .

Your n8n lookup table exercise

Build an n8n lookup table that prepares a payload only when an incoming label has exactly one reference row, an approved code and an unexpired mapping. This is an editorial exercise based on documented capabilities: its fixtures, algorithm and expected results are proposals, with no supplied execution or validation.

Use synthetic data in your own n8n environment. You need Data Tables, permission to create a table, and familiarity with JavaScript Code nodes and IF branching. n8n documents Data Tables for workflow lookups and CSV import, but the supplied documentation establishes no minimum version or plan; check that your environment exposes the feature. Tables are project-scoped and intended for light to moderate storage.

Finish at separate eligible-payload and review outputs. HTTP configuration, authentication, actual writes and destination enforcement are outside scope. Completion means every input identifier appears exactly once, with the expected disposition below.

Sources: n8n-docs/docs/build/work-with-data/data-tables.md at main · n8n-io/n8n-docs · GitHub

Prepare reference rows and incoming records

Create a CSV with label, apiCode and expiresAt headers using the exact editorial fixture below, then import it into a Data Table named reference_codes. Blank's apiCode field is empty; Unknown has no reference row. Treat EXP, ECO, EC2, LEG and BRK as the exercise's approved-code set; these fictional codes establish nothing about an external API. Fix evaluation time at 2026-10-22T00:00:00Z.

label,apiCode,expiresAt Express,EXP,2027-01-01T00:00:00Z Economy,ECO,2027-01-01T00:00:00Z Economy,EC2,2027-01-01T00:00:00Z Legacy,LEG,2026-01-01T00:00:00Z Broken,BRK,not-a-date Blank,,2027-01-01T00:00:00Z Boundary,EXP,2026-10-22T00:00:00Z

Use the following incoming records for your n8n lookup table exercise. Match labels exactly, including case and whitespace.

Editorial incoming records
IdentifierLabel
r1Express
r2Economy
r3Legacy
r4Broken
r5Unknown
r6Blank
r7Boundary

Retrieve the table with Data Table Get and Return All enabled. Keep it unchanged throughout retrieval: n8n documents possible inconsistencies when edits occur during paginated retrieval. For this design, feed the retrieved workflow output into Code.

Sources: n8n-docs/docs/build/work-with-data/data-tables.md at main · n8n-io/n8n-docs · GitHub, n8n-docs/docs/integrations/builtin/core-nodes/n8n-nodes-base.datatable/rows.md at main · n8n-io/n8n-docs · GitHub

Suggested solution: preserve ambiguity before checking expiry

One hand lifts a token over a partly hidden token; a second tray holds two exposed tokens beside an hourglass.
Keeping duplicate mappings visible preserves the ambiguity that selecting a first match would hide.

Use this suggested serial arrangement: Incoming records → Get reference rows → Build index → Evaluate. Make Incoming records a Code node returning one item whose json contains a records array with all seven identifier-and-label objects. Get reference rows retrieves every row with a nonempty label and Return All enabled. n8n's Code guidance supports joining reference data to another dataset and returning workflow items as an array of { json: ... } objects.

Run Build index once for all items. Group $input.all() rows by exact label in a JavaScript Map named index, retaining arrays of complete reference rows, and return [{ json: { byLabel: Object.fromEntries(index) } }]. Economy's array must contain both rows. Run Evaluate once for all items: read the index from $input.first().json.byLabel and the original records from $('Incoming records').first().json.records. For each record, retrieve candidates with byLabel[record.label] ?? []. Iterate that records array, not the reference rows, so Unknown also receives a result. These worked examples show the proposed workflow items.

Editorial worked evaluations and proposed workflow items
InputEvaluationResult item
r1: ExpressOne match; EXP approved; expiry later than evaluation time{"json":{"identifier":"r1","label":"Express","eligibility":true,"reason":"eligible","payload":{"identifier":"r1","apiCode":"EXP"}}}
r2: EconomyTwo matches; reject before code or expiry checks{"json":{"identifier":"r2","label":"Economy","eligibility":false,"reason":"ambiguous"}}

For dates, n8n documents that values pass between nodes as strings and require parsing. In JavaScript, use Luxon DateTime.fromISO with an explicit UTC zone, inspect isValid, and compare toMillis() values. Luxon 3.7.2 documentation lists validity inspection and timestamp conversion; it does not establish the version bundled with your installation. Explicit UTC timestamps avoid relying on workflow timezone interpretation.

We think ambiguity deserves its own rejection reason: selecting a convenient row hides the decision the learner needs to inspect. Follow this proposed validation order.

  1. Group reference rows by exact label into arrays, preserving every duplicate. A JavaScript Map can hold each label and its array.
  2. For each incoming record, retrieve its matches. Emit missing for zero matches and ambiguous for more than one; stop evaluating that record.
  3. For the single match, require a string apiCode whose trimmed value is nonempty and whose original value belongs to the declared approved-code set. Otherwise emit invalid_code.
  4. Parse expiresAt. Emit invalid_expiry when parsing is invalid; otherwise emit expired when its timestamp is less than or equal to the evaluation timestamp.
  5. Emit one { json: result } item per input. Keep its identifier and label, eligibility and reason. Add payload containing the identifier and mapped apiCode only when eligible; otherwise omit payload and apiCode.

Sources: skills/skills/n8n-code-nodes-official/SKILL.md at main · n8n-io/skills · GitHub, n8n-docs/docs/build/work-with-data/handle-special-data-types/work-with-dates-and-times.md at main · n8n-io/n8n-docs · GitHub, luxon 3.7.2 | Documentation

Route results and inspect completion

Configure IF to send eligibility equal to true to the payload output and everything else to review. Suyash Raj's 2026 commercial implementation guide describes IF branching for valid and invalid records. Set node errors to Stop Workflow, which n8n documents as halting execution. Business rejections still require the explicit rules above.

Use Execute step to inspect lookup and validation outputs separately. Compare results against these editorial acceptance checks.

Sources: n8n-docs/docs/build/understand-workflows/workflow-components/work-with-nodes.md at main · n8n-io/n8n-docs · GitHub, n8n Data Validation & Cleaning Workflows | Suyash Raj

Reflect on the mapping decision

If results differ, inspect retrieved row counts, duplicate grouping, exact label spelling and parsed expiry values. Keep normalization out unless you explicitly apply the same rule to both datasets.

Explain what would happen if one Economy row expired but the other remained current. Under this exercise's rules, counting duplicates comes first, so the mapping remains ambiguous. Then explain why choosing the first match or supplying a default code would violate the contract.

In our view, an n8n lookup table should expose unresolved choices before a payload leaves the gate. This exercise does not establish atomicity with a later API write or protect against reference changes after lookup.

Put this into practice

Hands-on n8n challenges

Pick a challenge and build a working workflow in your own n8n environment, with five progressive tips per challenge.

Try a hands-on challenge

For your team

Custom n8n training programs for one team or department, run on your own n8n instance with your own tools and data.

Training for your team

n8n skills assessment

A free quiz of about 20 minutes: 30 questions in 10 skill areas and a level from Beginner to Expert. On AI Adoption Score, another project by the author of this site.

Get your n8n level