Skip to content
Daily API Digest

Module 02 · foundations · beginner

Solutions 02 · Daily API Digest

Exercise 1

In Settings, add q (String) = {{ ($json.query?.q ?? '').toLowerCase() }}.

In Popular Only, add a second condition (combinator AND):

  • Left: {{ $('Settings').first().json.q === '' || $json.title.toLowerCase().includes($('Settings').first().json.q) }}
  • Operator: Boolean → is true

Doing it in one boolean expression handles the "no q" case: an empty q passes everything.

Exercise 2

Tested on n8n 2.43.6:

  1. Open Popular Only → Settings tab → turn on Always Output Data. With zero matches it now outputs one empty item instead of nothing, so the flow continues.
  2. That empty item becomes a story with no title. In Add Summary, filter it out:
    • count = {{ $json.stories.filter(s => s.title).length }}
    • text = {{ $json.stories.filter(s => s.title).map(s => s.line).join('\n') }}
    • stories = {{ $json.stories.filter(s => s.title) }}

Result: {"date":"…","count":0,"text":"","stories":[]}.

This is why Sort sits before Filter: Sort errors on an item without points, while Limit and Edit Fields handle it.

Exercise 3

Example with Gmail (Send, operation Send):

  • To: your address
  • Subject: HN Digest {{ $json.date }}
  • Email Type: Text
  • Message: {{ $json.text }}

Connect it to the IF's false output in place of the No Operation node. Slack/Telegram are the same idea: put {{ $json.text }} in the message field.

Stretch

Add a second HTTP Request from Settings to Reddit, a Split Out on data.children, then an Edit Fields that maps data.title → title, data.score → points, data.url → url. Combine both lists with a Merge node (mode Append) before Most Points First.