How to change HTTP Response

I’m still learning Nodemation.
Is there anyone who knows how can I change the HTTP Response to this format?

{
“messages”: [
{
“text”: “Text Sample”
}
],
“actions”: [
{
“type”: “set_variable”,
“data”: {
“userName”: “testuser”,
“userPhone”: “+123456789”
}
}
]
}

I tried using Set Node (Keep Only Set), but I couldn’t find a way to change the response format
Set Node format is shown below:

[
{
“userName”: “testuser”,
“userPhone”: “+123456789”

         } 

]

This is the flow…
I wan to get data from google sheet and the webhook will return All Entries from the Last Node.
n8n_io_Workflow_Automation

I need to rewrite the data from google sheet to the format above as a Response Data.

I manage to set it up using Set Node

Now, what I need to do is how I can get the objects “messages” and " actions" out from first array

That has to be set on the Webhook-Node. If you set “Response Data” to “First Entry JSON” it should return exactly what you want.

1 Like

Perfect! Thanks! It worked!

Great to hear! Have fun!

Hi Jan, what if I want to send the Set Data to a POST HTTP Request, how can I select First Entry JSON as Body?

Please start the next time a new topic if you ask a question which is not about the current topic. Thanks!

You can send the data by setting “JSON/RAW Parameters” to true and “Body Parameters” to an expression with this value: {{$node["Set"].json}}

{
  "nodes": [
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "name",
              "value": "Jan"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        400,
        300
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://example.com",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "={{$node[\"Set\"].json}}"
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        550,
        300
      ]
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Thanks for the help.
I’ll create a new topic next time. Thanks again.

1 Like