In create workflow API how is the connection data set?

In create workflow API schema , connector structure is not clear.
eg. i have 2 nodes how do i pass the connection details ?

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @parinita.kumar, welcome to the community!

The best way of understanding the structure would be to first create the workflow you have in mind using the UI, then fetch it through the API.

That said, an example connection object could look like so:

"connections": {
    "Manual Execution": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },

This would describe a connection from a node named Manual Execution to the node named HTTP Request. The full request would look like so:

curl --request POST \
  --url https://instance_hostname/api/v1/workflows/ \
  --header 'Content-Type: application/json' \
  --header 'X-N8N-API-KEY: API-Key goes here' \
  --data '{
  "name": "Example workflow forum topic 29961",
  "nodes": [
    {
      "parameters": {},
      "name": "Manual Execution",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        820,
        340
      ]
    },
    {
      "parameters": {
        "url": "https://www.boredapi.com/api/activity",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1040,
        340
      ]
    }
  ],
  "connections": {
    "Manual Execution": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {}
}'

This would be the resulting workflow:

Hope this helps!

Hi @MutedJam thanks for the reply . However I was able to achieve that last day . I was missing one array previously and the connections were not getting generated. I used something like that and it worked. Thanks for the support :+1:
“connections”: {
“start”: {
“main”: [
[{
“node”: “Code”,
“type”: “main”,
“index”: 0
}]
]
},
“Code”: {
“main”: [
[{
“node”: “prism”,
“type”: “main”,
“index”: 0
}]
]
},

},

However I am yet to understand the purpose of Index here. Could you help me with that?

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.