Automation

How to Use the n8n HTTP Request Node for API Integration

Learn step-by-step how to utilize the n8n HTTP Request node for seamless API integration.

4 min read

Learn how to replace built-in integrations, such as the OpenWeatherMap node, with the flexible n8n HTTP Request node for seamless API integration.

Prerequisites

Before setting up the HTTP Request node in n8n, ensure the following:

prerequisites

  • n8n Installation: Access to an n8n instance (locally installed or cloud-hosted).
  • API Key: OpenWeatherMap API key (sign up at openweathermap.org).
  • Basic HTTP Knowledge: Familiarity with HTTP requests, including parameters, methods, and endpoints.
  • API Documentation Navigation: Ability to read and interpret API documentation.

Steps to Replace OpenWeatherMap Node with HTTP Request Node

This section demonstrates how to replace the existing OpenWeatherMap node in n8n with the generic HTTP Request node to retrieve weather data.

steps

  1. Remove the OpenWeatherMap Node:

    • Disable the existing OpenWeatherMap node by clicking the "Disable" button.
    • Unlink the node by removing input/output connections, then delete it from the workflow.
  2. Review OpenWeatherMap API Documentation:

    • Visit the OpenWeatherMap API documentation and locate the endpoint that retrieves weather data by city name. Here's an example URL format:
      https://api.openweathermap.org/data/2.5/weather?q={CITY_NAME}&appid={API_KEY}&units={UNIT}
    • Note that the API requires query parameters for q (city name), appid (API key), and optionally units (e.g., metric for Celsius).
  3. Add the HTTP Request Node:

    • Click the “+” button in the n8n workflow editor and search for the HTTP Request node.
    • Add it to your workflow where the OpenWeatherMap node was previously connected.
  4. Configure the HTTP Request Node:

    • Set the HTTP Method to GET (the method required by the OpenWeatherMap API).
    • In the URL field, enter the base URL:
      https://api.openweathermap.org/data/2.5/weather
    • Enable the Send Query Parameters option.
  5. Add Query Parameters:

    • Click "Add Parameter" and provide the following keys and example values (replace with your actual API key):
      • Name: q, Value: Toronto
      • Name: appid, Value: YourOpenWeatherMapAPIKey
      • Name: units, Value: metric
  6. Test the Setup:

    • Click the “Execute Node” button to send a test request.
    • Verify the response in the node's output. You should see JSON data containing weather details for the specified city.
  7. Dynamic City Input via Webhook:

    • Add a Webhook node before the HTTP Request node to accept city inputs dynamically.
    • Reconnect the Webhook node to the HTTP Request node and update the q parameter to reference the Webhook's input field (e.g., "city").
  8. Finalize and Test Workflow:

    • Save and test the workflow by triggering the Webhook with different city names (e.g., ?city=Rome).
    • Validate that the HTTP Request responds accurately with weather data for the specified city.

Common Mistakes and Troubleshooting

Keep an eye out for the following hurdles when setting up the HTTP Request node:

Verification and Test Results

To ensure the workflow functions correctly:

FAQ

How do I use the n8n HTTP Request node to replace a built-in integration?

To replace a built-in integration like the OpenWeatherMap node, add an HTTP Request node to your workflow, set the method to GET, and customize the endpoint URL with relevant query parameters following the API's documentation.

How do I dynamically add query parameters in n8n HTTP Request nodes?

Enable the Send Query Parameters option in the HTTP Request node. Then, use the "Add Parameter" option to specify each parameter key-value pair. You can make values dynamic by mapping data from previous nodes into the parameter fields.

What should I do if my HTTP Request node returns an error?

Start by checking the API's documentation to verify the endpoint URL, HTTP method, and required parameters. If the setup looks correct, ensure your API key is valid and that your input data (e.g., dynamic variables) match the expected format.