How to combain/merge http requst nodes output json data to http request input

Hello !

I’m trying to create management workflow using the management REST API. My flow has in moment two HTTP request nodes that worked as expected but i have problem how to create json input to my third http request node 3 to make api request. This third requires HTTP request node 3 REST API request requires output data from first HTTP request node 1 or function node 1 and second HTTP request node 2.
My flow is following:

The second HTTP requst node 2 makes REST API request:
https://127.0.0.1:4000/api/v1/clients/{{$json[“id”]}}/tls-certificates

The second HTTP request node node 2 makes REST API request returns empty json valu [] if there is now match for {$json[“id”] . Example of HTTP request node node 2 output:
http-request-node-output

Function node 1 output:
Screenshot-function-node-1-output

The third HTTP request node 3 REST API requets must look like this
https://127.0.0.1:4000/api/v1/clients/{{$json[“id”]}}/tls-certificates{{$json[“hash”]}}
With data for example>
https://127.0.0.1:4000/api/v1/clients/ee-dev:COM:10264823:10264823-ANDMEVARA/tls-certificates/C122A11AAA6ECEF455771CC0C9EE2ED7894C68A9

Is possible some how merge/combain these outputs to one json input to the third HTTP request node 3 This Combaining/merge must also eliminate these blank json values that came from HTTP request node 2 outputs.

Lauri-Alo Adamson

Hey @alolauri , acutally, you can use the Function node in order to remove the empty arrays from your outputs and then use the Merge node (twice one to combine data of first HTTP request & function node, second for to combine data of the merge node and the second HTTP request). Ofcourse, you can choose the right merge style to meet your needs.

Your workflow may look similar to this one

1 Like

Many thanks for reply , here is my clarification for subject

This third http request node 3 input must be the pair of values [{{$json[“id”]}] and {{$json[“hash”]}} where the [{{$json[“id”]}] value input produces the in HTTP request node 2 output which has not empty output with {{$json[“hash”]}} value.

The second HTTP requst node 2 makes REST API request:
https://127.0.0.1:4000/api/v1/clients/ee-dev:COM:10264823:10264823-ANDMEVARA

The third HTTP requst
https://127.0.0.1:4000/api/v1/clients/ee-dev:COM:10264823:10264823-ANDMEVARA/tls-certificates/C122A11AAA6ECEF455771CC0C9EE2ED7894C68A9

I’m little bit confused how combaining merge and function nodes produce disired result.

Hi @alolauri !

Perhaps I’m misunderstanding, but this sounds like something you can do quite simply with expressions. You can create an expression for the URL on your second HTTP request node by clicking on the ‘cog’ icon to the right of the field and choosing ‘add expression’

image

Hey @alolauri!

I’ve created a sample workflow that might be useful for you. In this workflow, I am using the Function nodes to generate dummy data. Make sure to update the code in these nodes. Since I don’t have access to the API, I am not able to execute the workflow. However, this workflow should give you a hint and help you :slight_smile:
(You can copy the below code and paste it in your workflow editor!)

{
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        500,
        250
      ]
    },
    {
      "parameters": {
        "url": "=https://127.0.0.1:4000/api/v1/clients/{{$json[\"id\"]}}/tls-certificates",
        "options": {}
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        900,
        100
      ]
    },
    {
      "parameters": {
        "functionCode": "// Code here will run only once, no matter how many input items there are.\n// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.function\n\n// Loop over inputs and add a new field called 'myNewField' to the JSON of each one\nreturn [{\n  json: {\n    \"id\": \"123\"\n  }},\n  {\n  json: {\n    \"id\": \"1234\"\n  }\n}\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        700,
        250
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{\n  json: {\n    \"hash\": \"1asdfasdf23\"\n  }},\n  {\n  json: {\n    \"hash\": \"12asdfa3asf4\"\n  }\n}\n]\n"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1100,
        100
      ]
    },
    {
      "parameters": {
        "mode": "mergeByIndex"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1350,
        250
      ]
    },
    {
      "parameters": {
        "url": "=https://127.0.0.1:4000/api/v1/clients/{{$json[\"id\"]}}/tls-certificates/{{$json[\"hash\"]}}",
        "options": {}
      },
      "name": "HTTP Request2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1550,
        250
      ]
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Many thanks for help and examples.

I experimented with merge and function nodes , my flow looks like this modified variant as suggested in replay

I got the errror in 404 in REST API request because i could not create correct pair of values with merge and function nodes for HTTP request input .

This third http request node 3 input must be the pair of values [{{$json[“id”]}] and {{$json[“hash”]}} where the [{{$json[“id”]}] value input produces the in HTTP request node 2 output which has not empty output with {{$json[“hash”]}} value.

My Function node 1 java script is following:
Screenshota-Javascript-code-2021-06-30 15-01-52

My Function node 1 output sample:
Screenshot-function1-output

HTTP request1 node output and Function1 node input sample:
http-request-node-output

Merge1 node config and out put example:

What is correct way to use function/merge nodes ( and expressions) to get correct merge output to generate correct pairs of json valuses to make corcest REST API request with HTTP request2 node.

Lauri