HTTP request helper for node builders#
n8n provides a flexible helper for making HTTP requests, which abstracts away most of the complexity.
Programmatic style only
The information in this document is for node building using the programmatic style. It doesn't apply to declarative style nodes.
Usage#
Call the helper inside the execute
function.
1 2 3 4 5 6 7 8 9 |
|
options
is an object:
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 27 |
|
url
is required. The other fields are optional. The default method is GET
.
Some notes about the possible fields:
body
: you can use a regular JavaScript object for JSON payload, a buffer for file uploads, an instance of FormData formultipart/form-data
, andURLSearchParams
forapplication/x-www-form-urlencoded
.headers
: a key-value pair.- If
body
is an instance ofFormData
then n8n addscontent-type: multipart/form-data
automatically. - If
body
is an instance ofURLSearchParams
, then n8n addscontent-type: application/x-www-form-urlencoded
. - To override this behavior, set a
content-type
header.
- If
arrayFormat
: if your query string contains an array of data, such asconst qs = {IDs: [15,17]}
, the value ofarrayFormat
defines how n8n formats it.indices
(default):{ a: ['b', 'c'] }
asa[0]=b&a[1]=c
brackets
:{ a: ['b', 'c'] }
asa[]=b&a[]=c
repeat
:{ a: ['b', 'c'] }
asa=b&a=c
comma
:{ a: ['b', 'c'] }
asa=b,c
auth
: Used for Basic auth. Provideusername
andpassword
. n8n recommends omitting this, and usinghelpers.httpRequestWithAuthentication(...)
instead.disableFollowRedirect
: By default, n8n follows redirects. You can set this to true to prevent this from happening.skipSslCertificateValidation
: Used for calling HTTPS services without proper certificatereturnFullResponse
: Instead of returning just the body, returns an object with more data in the following format:{body: body, headers: object, statusCode: 200, statusMessage: 'OK'}
encoding
: n8n can detect the content type, but you can specifyarrayBuffer
to receive a Buffer you can read from and interact with.
Example#
For an example, refer to the Mattermost node.
Deprecation of the previous helper#
The previous helper implementation using this.helpers.request(options)
used and exposed the request-promise
library. This was removed in version 1.
To minimize incompatibility, n8n made a transparent conversion to another library called Axios
.
If you are having issues, please report them in the Community Forums or on GitHub.
Migration guide to the new helper#
The new helper is much more robust, library agnostic, and easier to use.
New nodes should all use the new helper. You should strongly consider migrating existing custom nodes to the new helper. These are the main considerations when migrating:
- Accepts
url
. Doesn't accepturi
. encoding: null
now must beencoding: arrayBuffer
.rejectUnauthorized: false
is nowskipSslCertificateValidation: true
- Use
body
according tocontent-type
headers to clarify the payload. resolveWithFullResponse
is nowreturnFullResponse
and has similar behavior