{
  "name": "twenty-sync",
  "nodes": [
    {
      "parameters": {},
      "id": "a1b2c3d4-0001-0000-0000-000000000001",
      "name": "When Called By Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.action }}",
                    "rightValue": "create_task",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "create_task"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.action }}",
                    "rightValue": "create_note",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "create_note"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.action }}",
                    "rightValue": "update_task",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "update_task"
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0001-0000-0000-000000000002",
      "name": "Route by Action",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.TWENTY_BASE_URL }}/api",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "json",
        "body": {
          "query": "mutation CreateTask($input: TaskCreateInput!) { createTask(data: $input) { id title status createdAt } }",
          "variables": {
            "input": {
              "title": "={{ $('When Called By Another Workflow').item.json.data.title }}",
              "body": "={{ $('When Called By Another Workflow').item.json.data.body }}",
              "status": "={{ $('When Called By Another Workflow').item.json.data.status ?? 'TODO' }}",
              "dueAt": "={{ $('When Called By Another Workflow').item.json.data.dueAt }}"
            }
          }
        },
        "options": {
          "retry": {
            "enabled": true,
            "maxTries": 3,
            "waitBetweenTries": 2000
          }
        }
      },
      "id": "a1b2c3d4-0001-0000-0000-000000000003",
      "name": "Twenty: Create Task",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        680,
        180
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.TWENTY_BASE_URL }}/api",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "json",
        "body": {
          "query": "mutation CreateNote($input: NoteCreateInput!) { createNote(data: $input) { id title body createdAt } }",
          "variables": {
            "input": {
              "title": "={{ $('When Called By Another Workflow').item.json.data.title }}",
              "body": "={{ $('When Called By Another Workflow').item.json.data.body }}"
            }
          }
        },
        "options": {
          "retry": {
            "enabled": true,
            "maxTries": 3,
            "waitBetweenTries": 2000
          }
        }
      },
      "id": "a1b2c3d4-0001-0000-0000-000000000004",
      "name": "Twenty: Create Note",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        680,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.TWENTY_BASE_URL }}/api",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "json",
        "body": {
          "query": "mutation UpdateTask($id: ID!, $input: TaskUpdateInput!) { updateTask(id: $id, data: $input) { id title status } }",
          "variables": {
            "id": "={{ $('When Called By Another Workflow').item.json.data.id }}",
            "input": {
              "status": "={{ $('When Called By Another Workflow').item.json.data.status }}"
            }
          }
        },
        "options": {
          "retry": {
            "enabled": true,
            "maxTries": 3,
            "waitBetweenTries": 2000
          }
        }
      },
      "id": "a1b2c3d4-0001-0000-0000-000000000005",
      "name": "Twenty: Update Task",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        680,
        420
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "success",
              "value": true
            },
            {
              "name": "record_id",
              "value": "={{ $json.data?.createTask?.id ?? $json.data?.createNote?.id ?? $json.data?.updateTask?.id }}"
            },
            {
              "name": "record_type",
              "value": "={{ $('When Called By Another Workflow').item.json.action }}"
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0001-0000-0000-000000000006",
      "name": "Format Response",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        300
      ]
    }
  ],
  "connections": {
    "When Called By Another Workflow": {
      "main": [
        [
          {
            "node": "Route by Action",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Action": {
      "main": [
        [
          {
            "node": "Twenty: Create Task",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Twenty: Create Note",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Twenty: Update Task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Twenty: Create Task": {
      "main": [
        [
          {
            "node": "Format Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Twenty: Create Note": {
      "main": [
        [
          {
            "node": "Format Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Twenty: Update Task": {
      "main": [
        [
          {
            "node": "Format Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": [
    {
      "name": "seo"
    },
    {
      "name": "twenty"
    },
    {
      "name": "sub-workflow"
    }
  ]
}