AI Template Search
N8N Bazar

Find n8n Templates with AI Search

Search thousands of workflows using natural language. Find exactly what you need, instantly.

Start Searching Free
Sep 10, 2025

n8n Webhook → GraphQL Country Lookup

n8n Webhook → GraphQL Country Lookup: Turn a Simple API Into a Powerful Automation Every automation journey starts with a small, practical step. This n8n workflow is one of those steps. It takes a simple idea – look up country information from a code – and turns it into a reusable, reliable building block you […]

n8n Webhook → GraphQL Country Lookup

n8n Webhook → GraphQL Country Lookup: Turn a Simple API Into a Powerful Automation

Every automation journey starts with a small, practical step. This n8n workflow is one of those steps. It takes a simple idea – look up country information from a code – and turns it into a reusable, reliable building block you can plug into bigger systems.

In this guide, you will walk through a compact n8n workflow that:

  • Accepts a country code through a webhook
  • Queries a public GraphQL API for country details
  • Returns a clear, human friendly response

It is a tiny workflow with big potential. Use it for quick lookups, demos, internal tools or as the first step toward more advanced automations that save you time and mental energy.

From Manual Lookups To Automated Clarity

Think about how often you or your team need country related information. It might be when:

  • Enriching user profiles with country details on signup
  • Validating customer data in forms or CRMs
  • Building small internal tools for support or sales
  • Creating demos or prototypes that need geographic context

Doing this manually or writing custom scripts every time is distracting and repetitive. With n8n and this GraphQL country lookup template, you turn a boring task into a reusable microservice.

The mindset shift is simple but powerful: instead of asking “How do I do this again?” you start asking “How can I automate this so I never have to think about it again?”

The Mindset: Start Small, Build Momentum

You do not need a massive, complex automation to see value. This workflow is intentionally small. It is made of only four nodes, yet it teaches you how to:

  • Receive external data through a Webhook
  • Call a GraphQL API from n8n
  • Parse JSON responses in a Function node
  • Shape the output to match your needs

Once you understand this pattern, you can reuse it everywhere. Today it is country information. Tomorrow it might be user enrichment, CRM syncing or internal dashboards. Each small workflow builds your confidence and frees more of your time for deep, meaningful work.

What This n8n Workflow Actually Does

At its core, the template connects a webhook to a public GraphQL API and formats the response. The node chain looks like this:

  1. Webhook – receives an HTTP GET request with a code query parameter, for example ?code=us
  2. GraphQL – calls https://countries.trevorblades.com/ with a query that uses this country code, converted to uppercase
  3. Function – parses the GraphQL JSON response and extracts the country object
  4. Set – builds a human friendly string that includes the country name, emoji and phone code

The result is a neat response like:

The country code of United States 🇺🇸 is 1

Simple, clear, and ready to plug into other systems.

What You Need Before You Start

You only need a few basics to follow along and adapt this workflow:

  • An n8n instance (cloud or self hosted)
  • Basic familiarity with n8n nodes and expressions
  • Optional tools like curl or a browser to test the webhook URL

If you are new to n8n, this is a perfect first template to explore. If you are experienced, it is a fast way to spin up a handy microservice.

Step 1: Receiving Data With The Webhook Node

The journey starts with the Webhook node. This is your workflow’s entry point, the place where other apps, scripts or services send the country code.

The Webhook node in this template is configured to:

  • Accept an HTTP GET request
  • Expose the query parameter code at query.code

So if you call:

https://your-n8n-host/webhook/webhook?code=us

the Webhook node will make us available to the rest of the workflow as {{$node["Webhook"].data["query"]["code"]}}.

This pattern is very powerful. Once you are comfortable with it, you can trigger workflows from almost anywhere with a simple HTTP request.

Step 2: Querying The GraphQL API

Next, the GraphQL node turns that country code into real data. It calls the public API at https://countries.trevorblades.com/ and injects the incoming code into a GraphQL query.

The node uses an expression to uppercase the code, because the API expects uppercase country codes:

query {  country(code: "{{$node["Webhook"].data["query"]["code"].toUpperCase()}}") {  name  phone  emoji  }
}

This query requests three fields:

  • name – the full country name
  • phone – the phone calling code, for example 1 for the US
  • emoji – the country flag emoji

At this point, you already have a working Webhook to GraphQL integration. You are no longer manually looking up country data, n8n is doing it for you.

Step 3: Parsing The GraphQL Response In A Function Node

The GraphQL node returns its data as a JSON string inside items[0].json.data. To make this easy to use in later nodes, the template uses a Function node to parse and simplify the response.

The Function node runs this code:

items[0].json = JSON.parse(items[0].json.data).data.country;
return items;

This does two things:

  1. Parses the JSON string into a real JavaScript object
  2. Replaces the node’s JSON payload with the country object itself

After this step, you can directly reference values like:

  • {{$node["Function"].data["name"]}}
  • {{$node["Function"].data["emoji"]}}
  • {{$node["Function"].data["phone"]}}

This pattern of parsing and shaping API responses is central to building more advanced automations. Once you master it here, you can apply it to many other APIs.

Step 4: Crafting A Friendly Message With The Set Node

Finally, the Set node turns raw data into a clear, readable message. In the template, the Set node uses an expression like:

=The country code of {{$node["Function"].data["name"]}} {{$node["Function"].data["emoji"]}} is {{$node["Function"].data["phone"]}}

You can keep this wording as is or adjust it to match your use case. For example, you might prefer:

  • The phone code for [name] is [phone]
  • Or a structured JSON response instead of a single string

The important part is that you are in control. You decide how the data is presented, and you can change it at any time without touching the underlying API or infrastructure.

How To Test Your Workflow

Once the nodes are configured or you have imported the template, testing is quick:

  1. Import the workflow JSON into n8n using Workflow → Import from file or by pasting the JSON
  2. Activate or execute the workflow in n8n so the Webhook is listening
  3. Call the webhook URL shown in the Webhook node

For example, using curl:

curl "https://your-n8n-host/webhook/webhook?code=us"

Replace https://your-n8n-host and the path to match your n8n instance and webhook configuration. You should receive a response similar to:

The country code of United States 🇺🇸 is 1

At this moment, you have created a small but real API service using n8n. This is a foundation you can build on.

Taking It Further: Turn A Demo Into A Real Tool

Once the basic workflow is running, you can start shaping it into something that fits your real world needs. Here are some ideas to grow it from a demo into a reliable tool.

Return Structured JSON For Easier Integration

If you plan to call this workflow from other systems or frontends, a JSON response is often more useful than plain text. You can:

  • Replace the Set node content with a JSON object
  • Or use an HTTP Response node to send a structured JSON payload

For example, you might return:

{  "name": "United States",  "emoji": "🇺🇸",  "phone": "1"
}

This makes it easy for other services to consume and display the data in their own interfaces.

Add Error Handling To Make It Robust

Production ready automations are not only functional, they are resilient. You can strengthen this workflow by handling common error cases:

  • Check that query.code exists in the Webhook node and return a clear error if it is missing
  • Handle cases where the GraphQL API returns null for an unknown country code
  • Use an IF node or Merge node to branch on errors and return appropriate HTTP status codes like 4xx or 5xx

These small improvements turn a neat demo into a dependable service that your team can trust.

Protect Your Webhook: Security Considerations

Even simple workflows deserve good security practices, especially when exposed over the internet. Consider:

  • Restricting access to the webhook endpoint with an IP allowlist
  • Requiring an API key via a header or query parameter
  • Ensuring your n8n instance uses HTTPS and stays up to date

Building secure habits early will pay off as your automation library grows.

Plan For Growth: Rate Limiting And Caching

If you expect a high volume of requests, you can optimize your workflow to be lighter on external services and faster for users:

  • Cache results in a database, Redis or another storage node
  • Reuse cached country data instead of calling the public GraphQL API every time
  • Reduce the risk of hitting rate limits on the external API

With caching in place, your simple lookup service becomes both efficient and scalable.

Advanced Ideas To Expand Your Automation Skills

Once you are comfortable with the basics, this workflow can grow in several directions. Here are a few ideas to explore and experiment with:

  • Accept both 2 letter and 3 letter country codes, then normalize them before making the GraphQL call
  • Extend the GraphQL query to include more fields such as capital, currency, languages and continent
  • Use the workflow as a microservice inside a larger automation, for example to enrich user profiles with country details on signup

You can also modify the GraphQL query directly. For instance, to fetch additional fields:

query {  country(code: "{{$node["Webhook"].data["query"]["code"].toUpperCase()}}") {  name  phone  emoji  capital  currency  languages { name }  }
}

Each enhancement is another step in your automation journey, and each step builds your confidence to tackle more ambitious workflows.

Troubleshooting: Learning From What Breaks

Every builder runs into issues. When something fails, it is not a setback, it is an opportunity to understand n8n more deeply. If your workflow is not behaving as expected, check:

  • Is the Webhook node active and is the path exactly the one you are calling?
  • Can your n8n instance reach https://countries.trevorblades.com/ from its network environment?
  • Did you rename any nodes? If so, update expressions like {{$node["Webhook"].data[...]}} and {{$node["Function"].data[...]}} accordingly
  • Have you inspected node execution logs in n8n to see the raw payloads and responses?

Each debugging session makes you faster and more confident the next time you build or adjust a workflow.

From One Template To A Library Of Automations

This compact n8n workflow is more than a country lookup. It is a pattern you can reuse:

  • Receive a request
  • Call an external API
  • Transform the response
  • Return exactly what you need

Once you see how quickly you can glue a webhook to a GraphQL API and shape its output, you start spotting similar opportunities everywhere in your work.

Use this template as a stepping stone. Import it, run it, break it, fix it, and then extend it with caching, error handling or JSON responses. Each improvement is a small investment in a more focused, less repetitive workday.

Call to action: Import the workflow into your n8n instance, try a few country codes, and then customize it. Turn it into a microservice, wire it into your signup flow, or use it as a reference for your next API integration. If this helped you move one step closer to a more automated workflow, consider subscribing for more n8n tutorials and templates.

Happy automating, and keep building.

Leave a Reply

Your email address will not be published. Required fields are marked *

AI Workflow Builder
N8N Bazar

AI-Powered n8n Workflows

🔍 Search 1000s of Templates
✨ Generate with AI
🚀 Deploy Instantly
Try Free Now