Skip to main content

The http request node

The http request node sends HTTP requests to external web services or APIs. It supports several HTTP methods, ways of passing data, and authentication, and gives you flexible control over requests and responses.


http request node settings​

"Node Information" window of the http request node "paypal auth": method "POST", PayPal sandbox token link, "Object JSON", "Use Authentication" on with type "basic"

1. Name​

The node name.
It appears in the workspace and helps you identify the node.
If you leave it empty, the node is named http request.

Example:

  • Node name: Get Weather Data

2. Method​

The HTTP method used for the request. Choose it based on the operation you need to perform.

Available methods:

  • GET: Retrieve data.
  • POST: Send data.
  • PUT: Update data.
  • DELETE: Delete data.
  • HEAD: Retrieve response headers.

Example:

  • Method: POST

A static URL that the request is sent to.
To set the address dynamically, pass it in msg.url.

Example:

  • Link: https://api.example.com/data

4. Data​

Defines how input data is added to the HTTP request. The options are:

  1. Ignore (default):
    Input data isn't used in the request. If msg.payload exists, it's ignored.

    Example:
    If msg.payload contains a JSON object, it isn't included in the request.


  1. Add to query parameters:
    Data from msg.payload is converted to query parameters and appended to the URL.

    Example:
    If msg.payload contains:

    {
    "key1": "value1",
    "key2": "value2"
    }

    and Link is http://example.com/api, the resulting request is:
    GET http://example.com/api?key1=value1&key2=value2.


  1. Send as request body:
    Data from msg.payload is sent in the request body. This option suits the POST and PUT methods, which often carry data in the body.

    Example:
    If msg.payload contains:

    {
    "name": "John Doe",
    "email": "john.doe@example.com"
    }

    and the request method is POST, this data is sent in the request body.

5. Return​

Defines the format in which the node processes the server response.

Options:

  • String: The response is converted to a string (default).
  • Object JSON: If the server responds with JSON, it's automatically converted to a JavaScript object.
  • Binary Buffer: The response is returned as a binary buffer (useful for binary data such as images or files).

Example:

  • If you select Object JSON, the response
    {"status": "ok", "value": 42}
    is converted to:
    msg.payload = { status: "ok", value: 42 };

6. Use Authentication​

This checkbox enables built-in authentication (off by default). When you select it, the form shows a Type field for the authentication method (basic by default):

basic​

  • Username: The username.
  • Password: The password.

bearer​

  • Password: The access token.

digest​

  • Username: The username.
  • Password: The password.

Input​

The http request node accepts a msg message object with these properties:

  1. msg.url: The request URL (if it isn't set in the node settings).
  2. msg.method: The HTTP method (if it isn't set in the node settings).
  3. msg.payload: The request body (used with POST and PUT).
  4. msg.headers: HTTP request headers (an object).

Output​

The node returns a msg object with information about the request:

  1. msg.payload: The server response data.
  2. msg.statusCode: The HTTP status code of the response (for example, 200 or 404).
  3. msg.headers: The response headers.
  4. msg.responseUrl: The URL the request was sent to.
  5. msg.error: An error description (if the request failed).

Examples​

Example 1: Sending a GET request​

Node settings:

  • Method: GET
  • Link: https://api.weatherapi.com/v1/current.json?key=API_KEY&q=London

Flow:

[inject] ---> [http request] ---> [debug]

Result: The node returns JSON with the current weather.


Example 2: Sending data with POST​

Node settings:

  • Method: POST
  • Link: https://api.example.com/devices
  • Data: Send as request body

Flow:

[function] ---> [http request] ---> [debug]

Code in the function node:

msg.payload = {
deviceId: "sensor123",
status: "active"
};
msg.headers = { "Content-Type": "application/json" };
return msg;

Result: The data is sent, and the node returns the server response.


Example 3: Dynamic URL and authentication​

Node settings:

  • Link: (leave empty)

Flow:

[function] ---> [http request] ---> [debug]

Code in the function node:

msg.url = "https://api.example.com/user/123";
msg.headers = { Authorization: "Bearer YOUR_TOKEN" };
return msg;

Result: The node sends a request to the specified URL with the authentication token.