{
  "id": "Kugz0eUALJGUsGQQ",
  "createdAt": "2023-07-20T13:30:44.896Z",
  "updatedAt": "2023-07-20T13:32:02.289Z",
  "name": "[Oscar] addNewBusinessLogged",
  "active": true,
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "https://cumplo.fapro.app/api/v1.0/login",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "email",
              "value": "api@cumplo.com"
            },
            {
              "name": "password",
              "value": "TKB6Thdmt2WacP3B8z9h"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      },
      "id": "c471a076-7f98-4fa0-a87f-02f1907fa7d3",
      "name": "LogginFapro",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2640,
        860
      ],
      "typeVersion": 3
    },
    {
      "parameters": {
        "url": "https://cumplo.fapro.app/api/v1.0/company/connected",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "authorization",
              "value": "=Bearer {{ $json[\"data\"][\"accessToken\"] }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      },
      "id": "8d44ee35-2c48-44c2-bf59-2b3b241601a7",
      "name": "GetBusinessLogged",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2400,
        860
      ],
      "typeVersion": 3
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "number": [
            {
              "name": "rut",
              "value": "={{ parseInt($json[\"empresa\"][\"rut\"]) }}-{{ $json[\"empresa\"][\"dv\"].toUpperCase() }}"
            }
          ],
          "string": [
            {
              "name": "RznSocial",
              "value": "={{ $json[\"empresa\"][\"rznSocial\"] }}"
            }
          ]
        },
        "options": {}
      },
      "id": "76037c23-44f4-42c5-a8ee-d59a990f41d1",
      "name": "BussinessActive",
      "type": "n8n-nodes-base.set",
      "position": [
        -2020,
        860
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field\n// called 'myNewField' to the JSON of each one\n//input all, el input es uno solo, el input all trae todo los inputs de ese nodo, en este caso es uno. s epuede tener varios items.\n\nvar data = []\nfor (const item of $input.all()) {\n  \n  data = item.json.data.companies.map(\n    (account) => {\n      return {\n        empresa:{\n      rut: account.rut.substring(0, account.rut.length -2),\n          dv: account.rut.substring(account.rut.length,account.rut.length-1 ),\n          rutdv:account.rut.substring(0, account.rut.length -2)+account.rut.substring(account.rut.length,account.rut.length-1 ),\n       rznSocial: account.razon_social.toUpperCase()\n       }\n      }\n    })\n}\n\nreturn data;"
      },
      "id": "d47192a4-85f9-4db9-9ba4-0989165755b2",
      "name": "ParseRut",
      "type": "n8n-nodes-base.code",
      "position": [
        -2200,
        860
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 7
            }
          ]
        }
      },
      "id": "245f3871-aebe-456d-8bf6-6cd3930e8c89",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -3000,
        1040
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "select rut from buroCL_buro_empresa bcbe order by 1 desc;\n",
        "options": {}
      },
      "id": "d0acbb8d-473c-4cbc-ba06-fc66c8fba46f",
      "name": "MySQL",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        -2620,
        1420
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mergeByFields": {
          "values": [
            {
              "field1": "rut",
              "field2": "rut"
            }
          ]
        },
        "resolve": "preferInput1",
        "options": {}
      },
      "id": "9b081afe-f8df-4f19-bbe4-5bea95ccfe26",
      "name": "Compare Datasets",
      "type": "n8n-nodes-base.compareDatasets",
      "typeVersion": 2.3,
      "position": [
        -1780,
        1140
      ]
    },
    {
      "parameters": {
        "table": {
          "__rl": true,
          "value": "buroCL_buro_empresa",
          "mode": "list",
          "cachedResultName": "buroCL_buro_empresa"
        },
        "dataMode": "defineBelow",
        "valuesToSend": {
          "values": [
            {
              "column": "rut",
              "value": "={{ $json.rut }}"
            },
            {
              "column": "razon_social",
              "value": "={{ $json.RznSocial.toUpperCase() }}"
            },
            {
              "column": "created_at",
              "value": "={{ new Date().toISOString() }}"
            },
            {
              "column": "updated_at",
              "value": "={{ new Date().toISOString() }}"
            }
          ]
        },
        "options": {}
      },
      "id": "4e8480bb-162b-4e69-8c4b-bcff508d0127",
      "name": "MySQL1",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        -1500,
        1100
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "LogginFapro": {
      "main": [
        [
          {
            "node": "GetBusinessLogged",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GetBusinessLogged": {
      "main": [
        [
          {
            "node": "ParseRut",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ParseRut": {
      "main": [
        [
          {
            "node": "BussinessActive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "LogginFapro",
            "type": "main",
            "index": 0
          },
          {
            "node": "MySQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MySQL": {
      "main": [
        [
          {
            "node": "Compare Datasets",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "BussinessActive": {
      "main": [
        [
          {
            "node": "Compare Datasets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compare Datasets": {
      "main": [
        [
          {
            "node": "MySQL1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveDataErrorExecution": "none",
    "saveDataSuccessExecution": "none",
    "saveManualExecutions": false,
    "callerPolicy": "workflowsFromSameOwner"
  },
  "staticData": {
    "node:Schedule Trigger": {
      "recurrencyRules": []
    }
  },
  "versionId": "51905465-24d9-44a9-abdb-dda209f29ef7",
  "triggerCount": 1,
  "tags": []
}