Skip to content

HTTP: send request

Plugin ID: eca_http_request

Available since: 3.1.10

Send an HTTP request and store the response in a token.

Sends an HTTP request to a URL and stores the response in a token. The action uses Drupal's http_client service, so it supports the methods GET, POST, PUT, PATCH, DELETE, and HEAD, a request body in raw, JSON, or form format, basic and digest authentication, a timeout, and a small number of retries.

It replaces the "Http Request" action of ECA Helper. See Migrating from ECA Helper.

The response token

Enter a name in "Name of response token" and the action stores the response there. The token has five keys:

Key Content
body The response body as a string.
json The decoded body, when it is valid JSON.
headers The response headers.
status The HTTP status code of the last attempt, or 0 when no response was received.
client_error 0 for a 2xx or 3xx response. 1 for a 4xx or 5xx response or a transport error, such as a failed connection or a timeout. 2 for a configuration or processing error, such as an invalid URL, invalid JSON in the body, or a response above the maximum size.

With a token named response, [response:status] is the status code and [response:json:id] reads the key id of a JSON response. To branch on failure, add the "Compare two scalar values" condition with [response:client_error] as the first value, the operator "greater than", the second value 0, and the comparison type "Numeric order". The condition is true for 1 and 2 and false for 0. Negate it to branch on success. Do not compare client_error for equality with 0: on success the token does not resolve to a value, so that comparison does not work.

For a 4xx or 5xx response, body, headers, and status carry the real response, so a model can read the error message the server sent. An action that fails with client_error 2 sends no request and logs the reason.

Tokens in requests

Token values never change the structure of a request. The action parses structured data first and replaces tokens in the parsed values afterwards, exactly once. This applies to:

  • the "Query parameters" and "Headers" fields, which are YAML mappings,
  • a body that uses the YAML option,
  • a body in the JSON format.

A token value that contains YAML syntax, quotes, line breaks, or JSON punctuation therefore stays one literal value. It cannot add a header, a query parameter, or another request option. Token values arrive exactly as they are, byte for byte.

Two rules follow from this order:

  • Quote tokens inside YAML and JSON. Write X-Api-Key: "[api_key]" and {"title": "[node:title]"}. A token inside JSON always arrives as a string, never as a number or a boolean.
  • The form format needs a YAML mapping. Set "Body format" to "Form", enable "Interpret the body as YAML format", and write the fields as a mapping. A form body without the YAML option, or a body that is not a mapping, is not sent and client_error is 2.

The URL and the username and password fields are plain strings, so tokens are replaced there directly. After replacement, the URL must use http or https and have a host.

Keeping credentials out of the model

Credentials typed into the "Username" and "Password" fields are stored in the model and exported with it. To keep a secret out of the exported configuration, use a token instead:

  1. Add the secret to settings.php as a configuration override, for example $config['my_module.settings']['api_password'] = '...';.
  2. Read it in the model with Config: read and "Include overridden" enabled, which is the default. Store it in a token, for example api_password.
  3. Enter [api_password] in the "Password" field, or use the token in a header such as Authorization.

The action never logs credentials, the query string, or the response body. Log messages contain the method and the URL without user information and query string.

NTLM and other authentication

The action offers basic and digest authentication. Digest relies on cURL options in Guzzle, so it requires the PHP cURL extension, which Drupal core does not require. Without it, no request is sent and client_error is 2. The configuration form shows a warning in that case.

NTLM is not part of the action. Guzzle deprecated its NTLM shortcut in version 7.12 and removes it in 8.0, and cURL builds increasingly ship without NTLM support. A site that needs NTLM can add it with a small custom module. Core adds every service tagged http_client_middleware to the http_client handler stack, so a tagged service can set the cURL options for one host. The credentials stay in settings.php, and the service applies to every request through http_client, including those of this action. It requires the cURL handler and a cURL build with NTLM support.

Declare the service in my_module.services.yml:

1
2
3
4
5
services:
  my_module.ntlm_middleware:
    class: Drupal\my_module\HttpClientMiddleware\NtlmMiddleware
    tags:
      - { name: http_client_middleware }

Add the service class in src/HttpClientMiddleware/NtlmMiddleware.php:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php

namespace Drupal\my_module\HttpClientMiddleware;

use Drupal\Core\Site\Settings;
use Psr\Http\Message\RequestInterface;

/**
 * Adds NTLM authentication to outgoing requests for one host.
 */
final class NtlmMiddleware {

  public function __invoke(): \Closure {
    return static function (callable $handler): \Closure {
      return static function (RequestInterface $request, array $options) use ($handler) {
        $ntlm = Settings::get('my_module_ntlm', []);
        if (isset($ntlm['host']) && $ntlm['host'] === $request->getUri()->getHost()) {
          $options['curl'][CURLOPT_HTTPAUTH] = CURLAUTH_NTLM;
          $options['curl'][CURLOPT_USERPWD] = $ntlm['username'] . ':' . $ntlm['password'];
        }
        return $handler($request, $options);
      };
    };
  }

}

Add the host and the credentials to settings.php:

1
2
3
4
5
$settings['my_module_ntlm'] = [
  'host' => 'crm.example.com',
  'username' => 'DOMAIN\\user',
  'password' => '...',
];

Rebuild the caches after enabling the module. Leave "Authentication" set to "None" in the action.

Timeouts and retries

"Timeout" applies to each attempt. "Retries" accepts 0 to 3 and retries only where a retry cannot process a request twice:

  • A connection failure, where the request never left, is retried for every method.
  • The status codes 429, 502, 503, and 504 are retried only for GET, HEAD, PUT, and DELETE. For POST and PATCH the server may already have processed the request.

The delay between attempts is 1, 2, and 4 seconds. When the response has a Retry-After header, that value is used instead. Either way, a delay never exceeds 5 seconds. The worst case is (retries + 1) * timeout plus the delays, so keep that sum below the time your request context allows, for example a web request.

For a slow endpoint or a longer back-off, move the request into ECA Queue instead of raising the retries. Check [response:client_error] after the action with the numeric "greater than" 0 check described above, and when it is true, re-enqueue the task with Enqueue a task with a delay and an attempt counter that stops the loop after a number of attempts.

Security limits

The action is deliberately narrow:

  • Only http and https URLs are sent. Other schemes, such as file:// or ftp://, are rejected.
  • Raw Guzzle request options are not available. The action builds the options from its own fields, and parsed YAML only fills the field it belongs to.
  • No field reads or writes a local file.
  • "Maximum response size" limits what is stored, 1 MiB by default. A larger response is not stored, an error is logged, and client_error is 2.

Migrating from ECA Helper

ECA Helper is unsupported since SA-CONTRIB-2026-193. When you update ECA, a post-update function converts every model that uses the ECA Helper action "Http Request". You do not need to edit the models by hand.

The conversion:

  • rewrites the action in the executable model and in the diagram, for models drawn with BPMN.iO or the Workflow Modeler, so that both stay in sync,
  • enables the ECA Base module when it is off,
  • works whether ECA Helper is still installed or not,
  • maps query_parameters to "Query parameters", data to "Body", the data serialization url_encode to the "Form" format, a timeout to "Timeout", and basic or digest authentication to the "Authentication" fields. The response token keeps its keys.

The update then reports what needs your attention:

  • Dropped settings. Settings without a safe equivalent are dropped: cookies, multipart uploads, NTLM authentication, and all other request options. The report lists the models and the names of the dropped settings, never their values. A Cookie header covers simple cases. For NTLM, see above.
  • Bodies to review. A JSON body that is not valid JSON before tokens are replaced, for example {"id": [node:nid]}, and a form body without the YAML option are carried over unchanged. They no longer work as before, because tokens are now replaced after parsing. Quote the tokens and enable the YAML option.
  • Models to convert manually. A model whose diagram cannot be rewritten automatically keeps the old action and is reported. Replace the action in these models yourself.

A timeout with a fractional value, such as 0.5, is rounded up to whole seconds.

Fields

Method — config key: method

Type: select · Required: yes · Default: get

Allowed values: get, post, put, patch, delete, head

URL — config key: url

The URL to send the request to. Supports tokens. After token replacement, the URL must use http or https and have a host, otherwise no request is sent.
This field supports tokens.

Type: textfield · Required: yes · Default: empty string

Query parameters — config key: query

A YAML mapping, for example page: 2. Supports tokens in keys and values, which are replaced after parsing. Wrap tokens in quotes, for example title: "[node:title]".
This field supports tokens.

Type: textarea · Required: no · Default: empty string

Headers — config key: headers

A YAML mapping, for example Accept: application/json. Supports tokens in keys and values, which are replaced after parsing. Wrap tokens in quotes, for example X-Api-Key: "[api_key]".
This field supports tokens.

Type: textarea · Required: no · Default: empty string

Body — config key: body

The request body. Supports tokens. With the JSON format, the body is decoded first and tokens are replaced in its string values afterwards, so tokens must be quoted inside JSON and arrive as strings, for example {"title": "[node:title]"}.
This field supports tokens.

Type: textarea · Required: no · Default: empty string

Interpret the body as YAML format — config key: use_yaml

When enabled, the body is parsed as YAML first and tokens are replaced in the parsed values. When using tokens and YAML altogether, make sure that tokens are wrapped as a string. Example: title: "[node:title]"

Type: checkbox · Required: no · Default: false

Validate YAML to prevent this from being executed when invalid — config key: validate_yaml

Type: checkbox · Required: no · Default: false

Body format — config key: body_format

Raw sends the body as it is. JSON sends the body as JSON. Form sends the body URL-encoded as form fields and requires the body as a YAML mapping, with the option above enabled.

Type: select · Required: yes · Default: raw

Allowed values: raw, json, form

Authentication — config key: auth_type

Basic sends an Authorization header. Digest requires the PHP cURL extension.

Type: select · Required: yes · Default: none

Allowed values: none, basic, digest

Username — config key: auth_username

Supports tokens. Values typed here are stored in the model and exported with the configuration. Use a token instead, for example from the "Config: read" action with "Include overridden" enabled, so that the secret can live in settings.php.
This field supports tokens.

Type: textfield · Required: no · Default: empty string

Password — config key: auth_password

Supports tokens. Values typed here are stored in the model and exported with the configuration. Use a token instead, for example from the "Config: read" action with "Include overridden" enabled, so that the secret can live in settings.php.
This field supports tokens.

Type: textfield · Required: no · Default: empty string

Timeout — config key: timeout

Seconds per attempt. With retries, the worst case is (retries + 1) * timeout, plus up to 5 seconds of delay between attempts. For a longer back-off, use ECA Queue: check [name:client_error] and re-enqueue with "Enqueue a task with a delay" and an attempt counter.

Type: number · Required: yes · Default: 30

Retries — config key: retries

Between 0 and 3. A connection failure is retried for every method. Status 429, 502, 503 and 504 are retried only for GET, HEAD, PUT and DELETE, because the server may already have processed other methods. The delay is 1, 2 and 4 seconds, or the Retry-After header, capped at 5 seconds.

Type: number · Required: yes · Default: 0

Maximum response size — config key: max_response_size

In bytes. A larger response is not stored, an error is logged and client_error is 2.

Type: number · Required: yes · Default: 1048576

Name of response token — config key: token_name

The response is stored in this token: [name:body] is the response body, [name:json] the decoded body when it is valid JSON, [name:headers] the response headers, [name:status] the status code (0 when no response was received) and [name:client_error] is 0 for a 2xx or 3xx response, 1 for a 4xx or 5xx response or a transport error and 2 for a configuration or processing error. Please provide the token name only, without brackets.

Type: textfield · Required: no · Default: empty string