HTTP request headers

Is there a way to get the headers of SUCCESSFUL https request?

Most of the threads and questions are on the ones that produce errors, but we’re not finding a way to check for headers of successful ones? Some sort of log of a request that was sent.

both - actual request and response headers that were sent are not visible (or we can’t find it).

Hi @ZilvinasB, welcome to the community! There is indeed a way to do this using the HTTP Request node. It comes with the Full Response option which would give you an additional headers field as well as the status code.

Found it for response. Thanks.

image

@MutedJam , the said option includes only the result, i.e. RESPONSE headers. However this option (or any other options) does not include full REQUEST headers that were sent to URL.

Hi @ZilvinasB. You’re right and I’m sorry to have missed that part of your question. The request headers aren’t returned as items by the HTTP Request node, but can be accessed through it’s parameters in subsequent nodes. E.g. when setting your headers as a JSON object in the HTTP Request node, you can read them in other nodes with an expression like {{JSON.parse($node["HTTP Request"].parameter["headerParametersJson"])}}:

This is an example workflow demonstrating the idea:

{
  "nodes": [
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "myRequestHeaders",
              "value": "={{JSON.parse($node[\"HTTP Request\"].parameter[\"headerParametersJson\"])}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://jsonplaceholder.typicode.com/posts",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "={\n  \"numeric\": 123,\n  \"text\": \"foo\",\n  \"date_text\": \"{{new Date().toISOString()}}\"\n}",
        "headerParametersJson": "{\n  \"user-agent\": \"my-n8n-workflow\",\n  \"x-some-random-header\": \"bar\"\n}"
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "myRequestHeaders",
              "value": "={{JSON.parse($node[\"HTTP Request\"].parameter[\"headerParametersJson\"])}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

I hope this helps! Give me a shout if you have any further queries on this!