n8n GraphQL Webhook: How One Marketer Started Fetching Country Info Fast
On a rainy Tuesday afternoon, Emma, a solo marketer at a fast-growing SaaS startup, stared at her screen in frustration. Her team had just launched a global campaign, and support tickets were piling up with questions like:
- “What is the phone code for Brazil?”
- “Can we show a country flag next to each lead’s phone number?”
- “Can the chatbot respond with country details instantly?”
Emma knew the data existed somewhere. She had heard about public GraphQL APIs that could provide country information. She also had an n8n instance running for other automations. What she did not have was time to hand-code a backend service or manually map country data for every lead.
She needed something lightweight, fast to prototype, and easy to plug into chatbots, forms, and internal tools. That is when she stumbled on an n8n template: a compact workflow that accepts a webhook request, queries a public GraphQL API for country info, and returns a friendly, human-readable response.
The Problem: Too Many Questions, Not Enough Automation
Emma’s challenge was simple to describe and annoying to solve. Every time a user entered a two-letter country code, she wanted to:
- Look up the country name
- Get the phone code
- Show the country’s emoji flag
She needed this for multiple use cases: a chatbot, a lead-enrichment form, and a small internal tool for the support team. Doing this manually or maintaining a static country list felt brittle and time-consuming. She wanted a reusable service that any tool could call with a single HTTP request.
Her requirements looked like this:
- A public webhook endpoint that any tool could hit
- A call to a reliable country GraphQL API
- A way to parse the JSON response and extract only what she needed
- A clean, human-friendly message as the final output
She already had an n8n instance, basic JavaScript knowledge, and internet access from her automations. The missing piece was a simple, structured workflow that tied everything together.
The Discovery: A Compact n8n GraphQL Webhook Template
While browsing for ideas, Emma found a template titled “Country info from GraphQL API” built with n8n. It promised exactly what she needed: a minimal workflow that accepts a webhook request, calls a public GraphQL endpoint, and returns country details in plain language.
The workflow used just four nodes, connected in a clean chain:
Webhook → GraphQL → Function → Set
Each node had a clear role, which made it easy for Emma to understand and customize:
- Webhook node to receive incoming HTTP requests with a country code
- GraphQL node to query a public API at
https://countries.trevorblades.com/ - Function node to parse the raw JSON response
- Set node to craft a short, readable message with the country name, emoji, and phone code
It was exactly the kind of compact, event-driven automation she had been looking for.
Setting the Stage: Prerequisites Emma Already Had
Before importing the template, Emma checked whether she had everything required:
- An n8n instance, either cloud or self-hosted (she was using n8n Cloud)
- Basic familiarity with JavaScript and n8n expressions
- Internet access from her n8n instance so it could call the public GraphQL API
With that confirmed, she imported the JSON template into n8n using Workflow → Import from JSON and opened it to see how it worked.
Rising Action: Building the Country Info Service Step by Step
1. The Webhook Node – Opening the Door
The first node in the workflow was a Webhook. This would be the public entry point that her chatbot, forms, or internal tools could call with a simple GET request.
She configured the path to something straightforward, like webhook. The template was set up so the Webhook accepted a query parameter named code, which represented the two-letter country code her tools would send.
Example request:
GET https://your-n8n.example.com/webhook/webhook?code=us
That meant any system could hit that URL with a ?code=XX parameter, and n8n would take care of the rest.
2. The GraphQL Node – Asking the Right Question
Next in the chain was the GraphQL node. This was where the real magic happened. The node called the public countries GraphQL API:
https://countries.trevorblades.com/
The template used an n8n expression to inject the incoming country code from the Webhook node into a GraphQL query and convert it to upper case, since the API expected codes like US or DE.
The query looked like this:
query { country(code: "{{$node["Webhook"].data["query"]["code"].toUpperCase()}}") { name phone emoji }
}
In the node settings, the template specified:
- Endpoint:
https://countries.trevorblades.com/ - Request method:
GET(n8n’s GraphQL node supports GraphQL over GET) - Response format:
string, so Emma could parse it herself in the next step
With this, the workflow could already take a country code like us and ask the GraphQL API for its name, phone code, and emoji.
3. The Function Node – Making JSON Usable
When Emma ran a test execution, she noticed that the GraphQL node returned a raw JSON string, not a neat object. To make that data easy to use for downstream nodes, the template added a small Function node.
The Function node contained this code:
// Function node code
items[0].json = JSON.parse(items[0].json.data).data.country;
return items;
This snippet did two key things:
- Parsed the raw JSON string from the GraphQL node
- Replaced the item’s JSON with the
countryobject
After this step, the item JSON contained a clean structure, something like:
{ "name": "United States", "phone": "1", "emoji": "🇺🇸"
}
Now any node after this could easily access name, phone, and emoji without extra parsing.
4. The Set Node – Crafting a Friendly Message
The final piece was the Set node. This was where Emma turned raw data into a message that humans and chatbots could use directly.
The template’s Set node used an expression to combine the values from the Function node into a short sentence. Conceptually, it looked like this:
data = The country code of {{$node["Function"].data["name"]}} {{$node["Function"].data["emoji"]}} is {{$node["Function"].data["phone"]}}
With Keep Only Set enabled, the node ensured that the final output only contained this crafted message, which would be returned as the webhook response.
In practice, a request like:
curl 'https://your-n8n.example.com/webhook/webhook?code=us'
would yield a response similar to:
{ "data": "The country code of United States 🇺🇸 is +1"
}
Emma realized she now had a tiny microservice that any of her tools could call to enrich country information on the fly.
The Turning Point: Testing and Debugging in Real Time
With the workflow in place, Emma wanted to make sure it behaved exactly as expected before wiring it into production tools. She started with simple tests.
Testing the Webhook
Using curl and her browser, she called the webhook endpoint with different country codes:
curl 'https://your-n8n.example.com/webhook/webhook?code=us'
curl 'https://your-n8n.example.com/webhook/webhook?code=de'
curl 'https://your-n8n.example.com/webhook/webhook?code=br'
Each time, she checked whether the response contained the correct country name, emoji flag, and phone code. When something looked off, she opened the Execution view in n8n and inspected each node’s output to see the intermediate JSON payloads.
Handling Common Issues
Along the way, she ran into a couple of typical problems and used these troubleshooting steps:
- GraphQL errors: If the GraphQL node returned an error, she checked the query syntax and verified that the expression used the right query parameter:
$node["Webhook"].data["query"]["code"] - JSON.parse failures: When the Function node complained about
JSON.parse, she confirmed that the GraphQL node’s Response format was set tostringand inspecteditems[0].json.datato confirm it held the raw JSON string - Undefined fields in the Set node: If the final message had missing values, she checked the Function node output to ensure it actually contained
name,phone, andemoji
With these checks, she quickly ironed out issues and gained confidence that the workflow was stable.
Raising the Bar: Security and Reliability
Once the template worked, Emma realized something important. Her webhook was a public endpoint. Anyone who knew the URL could hit it. That was powerful, but it also meant she needed to think about security.
She noted down a few best practices for hardening the workflow:
- Require an HMAC signature or API key as a query parameter or header before processing the request
- Whitelist allowed IPs or place the webhook behind a reverse proxy with authentication
- Validate that the
codeparameter is a two-letter ISO code before calling the GraphQL API - Add rate limiting or a secret token if exposing the endpoint publicly
By adding simple checks and guards, she could keep the convenience of a public webhook while avoiding obvious abuse.
From Prototype to Power Tool: Enhancements Emma Considered
With the basic workflow running smoothly, Emma’s imagination kicked in. The template had given her a solid foundation, but she saw more possibilities.
- More fields: She could extend the GraphQL selection set to include fields like
capital,continent, orlanguagesand return richer responses - Smart error handling: By adding a Switch node, she could detect invalid country codes or missing results and return a friendly error, instead of a confusing failure
- Caching: Since many requests would likely repeat the same country codes, she considered using an in-memory store or external cache to reduce API calls and speed up responses
- Microservice pattern: She realized this workflow could act as a tiny microservice for her chatbot, CRM, or internal tools, all powered by a single n8n template
What started as a simple way to answer country-related questions had turned into a reusable building block for her automation stack.
Resolution: A Simple Workflow, Big Impact
By the end of the week, Emma’s support team had stopped asking her for country codes. The chatbot could respond with country names, flags, and phone prefixes instantly. Her forms could enrich leads with country details automatically. And she did not have to maintain a bulky database or custom backend service.
All of this came from a compact n8n workflow that:
- Accepted a webhook request with a
codeparameter - Queried a public GraphQL API for country data
- Used a Function node to parse JSON responses
- Used a Set node to return a clear, human-readable message
The template showed her how n8n can orchestrate GraphQL calls, lightweight JavaScript parsing, and response formatting to deliver practical automation with very little effort.
Try the Same Workflow in Your Own Stack
If you want to replicate what Emma built, you can start with the same structure:
- Import the provided JSON template into n8n using Workflow → Import from JSON
- Configure the Webhook path and test it with:
curl 'https://your-n8n.example.com/webhook/webhook?code=us' - Inspect each node in Execution view if the output does not match your expectations
- Harden the webhook with security measures like signatures, API keys, or IP whitelisting
- Extend the GraphQL query or add nodes like Switch and cache to fit your exact use case
Ready to explore? Import the JSON, trigger the webhook with different country codes, and see how quickly GraphQL data can enhance your automations.
If you need help tailoring this workflow, for example:
- Adding authentication or signatures to the webhook
- Parsing more fields from the GraphQL response
- Integrating the output with Slack, a chatbot, or a CRM
Describe your use case, and you can adapt this template into a fully customized automation that fits your stack.
