{
  "id": "K3pHMAtPJKbB8jXo",
  "createdAt": "2023-09-06T13:49:01.793Z",
  "updatedAt": "2023-09-11T13:24:52.087Z",
  "name": "[CL] MKT Grandes Pagadores",
  "active": true,
  "nodes": [
    {
      "parameters": {
        "path": "edb39e00-59a9-47f1-8973-ee6bf3bcbc35",
        "options": {}
      },
      "id": "d4c49380-00f3-4d6a-a987-dfeaa896426c",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        300,
        740
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.hubapi.com/crm/v3/objects/companies/search/",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotAppToken",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"filterGroups\":[{\"filters\":[{\"value\":\"{{ $json.document_number }}\",\"propertyName\":\"rut_empresa\",\"operator\":\"EQ\"}]}],\"sorts\":[\"string\"],\"properties\":[\"rut\"],\"limit\":1,\"after\":0}  ",
        "options": {}
      },
      "id": "fcade618-5423-4daf-9d82-3124b7eb8aee",
      "name": "Search Hubspot Company",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        900,
        460
      ],
      "typeVersion": 3,
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "documento_tributario",
              "value": "={{ $json.query.rut_empresa }}"
            },
            {
              "name": "hs_object_id",
              "value": "={{ $json.query.hs_object_id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "124207bc-9d9f-4b8e-bc51-7620c04eb50a",
      "name": "Parsear",
      "type": "n8n-nodes-base.set",
      "position": [
        460,
        460
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.total }}",
              "operation": "equal"
            }
          ]
        }
      },
      "id": "30ff30ba-88ba-48cb-b804-0e5b11132596",
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "position": [
        1080,
        760
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "authentication": "appToken",
        "resource": "company",
        "name": "={{ $node.Code.json.document_number }}",
        "additionalFields": {
          "customPropertiesUi": {
            "customPropertiesValues": [
              {
                "property": "documento_tributario",
                "value": "={{ $node.Code.json.document_number }}"
              },
              {
                "property": "origen_de_cliente",
                "value": "[CL] MKT Grandes Pagadores"
              },
              {
                "property": "registro_grandes_pgadores",
                "value": "[CL] Grandes Pagadores"
              },
              {
                "property": "estado_empresa",
                "value": "Disponible"
              },
              {
                "property": "domain",
                "value": "={{ $node.Code.json.document_number }}.com"
              }
            ]
          }
        }
      },
      "id": "162b6dd1-472a-46ce-a99b-9eea86e05225",
      "name": "HubSpot",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        1280,
        500
      ],
      "typeVersion": 1,
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "CompanyId",
              "value": "={{ $json.companyId }}"
            }
          ]
        },
        "options": {}
      },
      "id": "04073f88-0671-4db9-bd20-812fa4f5caac",
      "name": "SetCompanyId",
      "type": "n8n-nodes-base.set",
      "position": [
        1520,
        500
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "CompanyId",
              "value": "={{ $json.results[0].id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "04b9bff7-7aa6-4f1c-b9fb-7d657851c9f3",
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "position": [
        1320,
        900
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "jsCode": "const documentoTributario = $input.first().json.documento_tributario;\nconst hsObjectId = $input.first().json.hs_object_id;\n\nconst rut = documentoTributario.replace(/\\./g, '').replace(/-/g, '');\n\nconsole.log(rut);\nreturn {\n  \"document_number\": rut,\n  \"hs_object_id\": hsObjectId\n};\n"
      },
      "id": "69ae3a95-7da0-4ab0-a7f1-c999f33680fd",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        640,
        460
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "=https://api.hubapi.com/crm/v3/objects/contact/{{ $node.Parsear.json.hs_object_id }}/associations/company/{{ $node.SetCompanyId.json.CompanyId}}/contact_to_company  ",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotAppToken",
        "options": {
          "response": {
            "response": {}
          }
        }
      },
      "id": "0130d74c-109f-49c2-9024-8f93d561471c",
      "name": "Link contact to company",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1760,
        500
      ],
      "typeVersion": 3,
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "=https://api.hubapi.com/crm/v3/objects/contact/{{ $node.Parsear.json.hs_object_id }}/associations/company/{{ $node.IF.json.results[0].id }}/contact_to_company  ",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotAppToken",
        "options": {
          "response": {
            "response": {}
          }
        }
      },
      "id": "51980f0d-42e5-4baf-b6ad-2c494ffa51fb",
      "name": "Link contact to company1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1540,
        900
      ],
      "typeVersion": 3,
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "authentication": "appToken",
        "resource": "company",
        "operation": "update",
        "companyId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $node.Set.json.CompanyId }}"
        },
        "updateFields": {
          "customPropertiesUi": {
            "customPropertiesValues": [
              {
                "property": "registro_grandes_pgadores",
                "value": "[CL] Grandes Pagadores"
              }
            ]
          }
        }
      },
      "id": "6594b82a-bc8a-4ce3-bcaf-fc3e9eb239e8",
      "name": "HubSpot1",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        1760,
        900
      ],
      "typeVersion": 2,
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "IF": {
      "main": [
        [
          {
            "node": "HubSpot",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Link contact to company1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "Search Hubspot Company",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HubSpot": {
      "main": [
        [
          {
            "node": "SetCompanyId",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parsear": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Parsear",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SetCompanyId": {
      "main": [
        [
          {
            "node": "Link contact to company",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Hubspot Company": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Link contact to company1": {
      "main": [
        [
          {
            "node": "HubSpot1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {},
  "staticData": null,
  "versionId": "5ffcb364-24c7-4695-b964-abe898b38f78",
  "triggerCount": 1,
  "tags": []
}