Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 27

Webhook-Triggered API Calls

Recommended resources

Introduction

In our previous lessons, you've become proficient at using Webhook nodes to both receive data from external systems and respond directly to the caller. This established a two-way communication channel. Today, we will build on that foundation to create one of the most powerful patterns in automation: using an incoming webhook event to trigger an API call to a completely different system.

This "Webhook -> API Call" architecture is central to CI/CD automation. A git push event can trigger a webhook, and your n8n workflow can then call the Jenkins API to start a build, the Jira API to update a ticket, or the GitHub API to create a pull request comment.

By the end of this lesson, you will be able to build a workflow that listens for a webhook and uses the data from that webhook's payload to dynamically construct and execute a request to an external API.


The "Webhook to API Call" Pattern

The core concept is a simple but powerful chain of events:

  1. An external event occurs (e.g., a code commit, a form submission, a chat message).
  2. The source system sends an HTTP request (a webhook) to an n8n Webhook node.
  3. Your n8n workflow extracts data from the incoming webhook payload.
  4. An HTTP Request node uses that extracted data to make a call to a target system's API, performing an action or fetching information.

This simple workflow visualizes the pattern perfectly: a webhook triggers an HTTP request.

A minimal n8n workflow showing the fundamental pattern: a Webhook node triggers an HTTP Request node.

A more concrete example related to your goals would be triggering a new software release.

This workflow is triggered by a Telegram command, which acts as the webhook event. It then uses the GitHub node, a specialized HTTP Request node, to call the GitHub API and create a release.

To implement this pattern, you will rely heavily on the HTTP Request node, which is n8n's universal tool for communicating with virtually any API on the web.


The HTTP Request Node

While n8n has many pre-built nodes for popular services (like the GitHub or OpenWeatherMap nodes), these are often just convenient wrappers around the generic HTTP Request node. Understanding this node is key to integrating with any custom, internal, or less-common API you might encounter.

The following article from Octave provides a great overview of the node's core components.

n8n HTTP Requests: Building Custom API Integrations - Octave HQ

This article explains the fundamentals of the HTTP Request node and provides practical examples.

First, read the section HTTP Request Node Fundamentals to understand the essential configuration options like URL, Method, Headers, and Body. Then, review Example 1: Custom Enrichment API. Pay close attention to how the Body of the POST request is constructed using an expression ({{ $json.company_domain }}) to include data from a previous step. This is the exact technique we will be using.


Seeing it in Action: A Practical Demonstration

The best way to understand this flow is to see it built. The following video demonstrates how to create a workflow that receives a city name via a webhook and uses it to call the OpenWeatherMap API to fetch the weather.

The video uses the pre-built OpenWeatherMap node, but the principle is identical: data from the webhook (query.city) is fed into a subsequent node to make a dynamic API call.

n8n Tutorial #4: Understanding Webhooks, If / Switch and API call Nodes

This clip from the "Understanding Webhooks, If / Switch and API call Nodes" tutorial by Ben Young AI provides a clear, step-by-step walkthrough.

First, watch the section that introduces the workflow and how the nodes are intended to work together from exploring the nodes. Next, and most importantly, watch the segment where the presenter debugs and successfully connects the webhook's input to the API node's parameter from connecting the data. This section masterfully illustrates how to pass data from a trigger to an action node using expressions.


Hands-On: Building a GitHub User Lookup API

Now, let's build a practical workflow that embodies this pattern. You will create a simple API that:

  1. Receives a GitHub username in a webhook POST request.
  2. Calls the public GitHub API to fetch that user's profile data.

This exercise requires no authentication, as we'll be accessing public data.

Your Task:

  1. Create a new workflow.

  2. Add a Webhook node.

    • Set the HTTP Method to POST.
    • Set the Path to something memorable, like github-user-lookup.
  3. Connect an HTTP Request node to the Webhook node.

    • The GitHub API endpoint for fetching a user's profile is https://api.github.com/users/USERNAME.
    • Set the Method to GET.
    • In the URL field, you need to dynamically insert the username received from the webhook. Assuming the incoming JSON is {"username": "some-user"}, the expression for the URL will be:
      https://api.github.com/users/{{ $json.body.username }}
  4. Test the workflow.

    • Click Listen for Test Event in the Webhook node.
    • Open your terminal and execute the following curl command, replacing <YOUR_TEST_URL> with the test URL from your Webhook node and "torvalds" with any public GitHub username.
    curl -X POST \
    -H "Content-Type: application/json" \
    -d '{"username": "torvalds"}' \
    '<YOUR_TEST_URL>'
    

After running the command, you should see the execution complete successfully in the n8n editor. Inspect the output of the HTTP Request node. It should contain the full JSON profile for the GitHub user you specified.


Conclusion

In this lesson, you have mastered the fundamental pattern of using a webhook to trigger an external API call. This is the cornerstone of event-driven automation and a critical skill for orchestrating complex CI/CD pipelines.

Key Takeaways:

  • The "Webhook -> API Call" pattern allows n8n to act as a reactive bridge between different systems.
  • The HTTP Request node is the generic tool for making API calls.
  • You can dynamically construct API requests (e.g., URLs, headers, bodies) using n8n expressions to reference data from preceding nodes, like a webhook trigger.

In our current workflow, we fetch the data from the GitHub API and the workflow simply ends. In our next lesson, we will extend this workflow to process the API response, extract key information, and return a custom, simplified summary to the original webhook caller, effectively completing the full API proxy pattern.