To send data from one API to another using n8n, you can chain together HTTP Request nodes (or a Webhook trigger + HTTP request) to receive, process, and forward data. Here's a full example:
โ
Scenario Example
Goal: Receive a POST request from API A โ forward specific data to API B.
๐ง Step-by-Step Setup
1. Trigger: Receive data from API A
2. Add a "Set" Node (optional)
- Use the Set node to extract or reshape the data as needed:
- Click "Add Field"
- Example:
- Name:
name, Value: {{$json["body"]["name"]}}
- Name:
email, Value: {{$json["body"]["email"]}}
3. Send to API B using "HTTP Request" node
๐ Optional: Handle API Bโs Response
- Connect a "Function" or "IF" node after the HTTP request to:
- Log or filter the result
- Trigger follow-up actions (email, Slack, etc.)
โ
Example Workflow Overview
[Webhook Trigger] โ [Set Data] โ [HTTP Request to API B] โ [Optional Logging or Alert]
๐งช Test It
- Set the workflow to Active.
- Send a test
POST to https://<your-n8n-domain>/webhook/receive-data.
- Watch the data flow through the workflow in the Execution view.
Sending data from one API to another using n8n is a core functionality and relatively straightforward. You'll primarily use the HTTP Request node for both fetching data from the first API and sending it to the second.
Here's a breakdown of the process:
1. Workflow Structure
A typical workflow for this scenario will look something like this:
Trigger Node: This is how your workflow starts. It could be:
- Webhook: If the first API sends data to n8n.
- HTTP Request: If n8n needs to proactively fetch data from the first API (e.g., a GET request).
- Schedule: To fetch data at regular intervals.
- Another application-specific trigger: If you're integrating with a service that has a dedicated n8n node (e.g., a "New Email" in Gmail, a "New Row" in Google Sheets).
HTTP Request Node (API 1 - Fetch Data): This node will make the call to your first API to retrieve the data you need.
Data Transformation/Manipulation Nodes (Optional but Common): After getting data from API 1, you might need to:
HTTP Request Node (API 2 - Send Data): This node will send the processed data to your second API.
2. Step-by-Step Guide
Let's assume you need to fetch data from "API A" and send it to "API B".
A. Triggering the Workflow & Fetching from API A
Add a Trigger Node:
- If API A sends data to n8n: Use a Webhook node. Configure it to listen for the appropriate HTTP method (GET, POST, etc.) and copy its URL. This is the URL API A will call.
- If n8n fetches data from API A: Use an HTTP Request node as your trigger (if it's a simple, one-off fetch or scheduled). Or, use a Schedule node followed by an HTTP Request node to periodically pull data.
Configure the HTTP Request Node for API A:
B. Preparing Data for API B (Transformation)
Inspect the Output: After running the HTTP Request node for API A, check the output in the n8n editor. This shows you the exact JSON structure of the data you received.
Add Data Transformation Nodes (if needed):
C. Sending Data to API B
Add another HTTP Request Node for API B:
- Drag a new HTTP Request node onto your canvas and connect it after your data preparation steps.
- Authentication: Configure the authentication for API B.
- HTTP Method: Set the method required by API B (often POST or PUT for sending data).
- URL: Enter the API B endpoint.
- Headers/Parameters: Add any specific headers or query parameters API B requires.
Construct the Request Body for API B:
Error Handling (Highly Recommended):
D. Saving and Activating
- Save Your Workflow: Give it a meaningful name.
- Activate Your Workflow: Toggle the "Active" switch in the top right. Your workflow is now live and will execute when its trigger is activated.
Key Concepts in n8n for Data Flow:
- Items: n8n workflows process data in "items." Each item represents a piece of data flowing through the workflow. Nodes typically operate on each incoming item.
- JSON Data: The primary data format within n8n is JSON.
- Expressions: These are powerful tools that allow you to dynamically access and manipulate data from previous nodes. They start with
{{ and end with }}.
{{ $json.propertyName }}: Access a property from the current item's JSON data.
{{ $node["Node Name"].json.propertyName }}: Access a property from a specific previous node's output.
{{ $node["Node Name"].json }}: Access the entire JSON output of a specific previous node.
{{ $items("Node Name")[0].json.propertyName }}: Access data from a specific item (e.g., the first item) from a previous node.
- Binary Data: For file uploads (e.g., sending an image from one API to another), n8n handles binary data. The HTTP Request node has options for sending "Form Data (multipart/form-data)" which allows you to include binary files.
By understanding these components and how data flows through n8n, you can build powerful and flexible integrations between virtually any APIs. Always refer to the API documentation of both your source and destination APIs to ensure you're sending and receiving data in the correct format and with the proper authentication.