If you want to connect an API to n8n or n8n VPS, it typically involves using the HTTP Request node within a workflow. The node allows interaction with external APIs by sending requests and receiving responses. Here’s a general guide on how to connect an API to n8n:
Step 1: Set Up n8n
- You can run on the local machine through npm, Docker, or user n8n.cloud (hosted version).
For npm:
npm install n8n -g
n8n
- Open http://localhost:5678 in your browser.
- Create a new workflow. Click on “New Workflow” in the n8n dashboard.
Step 2: Choose a Trigger Node
- Add a Trigger (e.g., Webhook Trigger) to trigger the workflow.
- Sample: Webhook: Use Webhook when you wish to make a call to the workflow through an external API.
Step 3: Add an HTTP Request Node
- This is the most important step in order to have connections to any API.
- Click “+” button, then choose “HTTP Request node.”
Set the API connection:
- Operation: GET, POST, PUT, DELETE (based on API).
- URL: Type in the API endpoint (e.g. https:api.example.com/data).
- Headers: Add Headers (e.g., Authorization: Bearer <API_KEY)).
- Query Parameters: Append parameters (e.g.,?limit=10&page=1).
- Body Parameters (POST/PUT): Add the JSON data or form-data according to the API documentation.
Step 4: Test the Connection
- Click “Execute Node”, which will execute the API call.
- With a success, the rendering of the JSON response of the API will appear in the output panel.
Step 5: Process the Data
- Increase API data processing nodes:
- Set Node – Retrieve or change fields.
- Function Node – Custom JavaScript.
- Database/Spreadsheet Node Save API data in your storage.
- Other API Node -Send the result to a new API.
Step 6: Save and Activate Workflow
- Click “Save” to save your workflow.
- Toggle “Activate Workflow” to be automatically activated.
Example: An interface to OpenWeather API.
Add Webhook Trigger → to begin on hitting the URL.
Add HTTP Request Node with:
- Method: GET
- URL: https://api.openweathermap.org/data/2.5/weather
- Query Parameters:
- q=London
- appid=<YOUR_API_KEY>
Open the node to retrieve weather information.
Action or response to Slack, email or database.