{
  "id": "k55IEnlMsxTEyqc6",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Syncro Asset Deduplication",
  "tags": [],
  "nodes": [
    {
      "id": "894f6c84-ff94-4655-a515-7a288af35750",
      "name": "Get all assets",
      "type": "n8n-nodes-syncrormm.syncroRmm",
      "position": [
        220,
        0
      ],
      "parameters": {
        "filters": {},
        "resource": "asset",
        "returnAll": true
      },
      "credentials": {
        "syncroRmmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d7069e31-0c50-4b60-a679-86acd85913f7",
      "name": "Get only duplicate serials",
      "type": "n8n-nodes-base.filter",
      "position": [
        1100,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "209ac15d-a686-402a-b9a2-96f45b6f7676",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.count_id }}",
              "rightValue": 1
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "b64e92bf-fa78-4c49-87be-a9ee2611de19",
      "name": "Count by serial number",
      "type": "n8n-nodes-base.summarize",
      "position": [
        880,
        0
      ],
      "parameters": {
        "options": {},
        "fieldsToSplitBy": "customer_id, asset_type, asset_serial",
        "fieldsToSummarize": {
          "values": [
            {
              "field": "id"
            },
            {
              "field": "link_label",
              "aggregation": "append"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "df84604b-c18f-42eb-a922-2c50e7a281ac",
      "name": "Create a ticket",
      "type": "n8n-nodes-syncrormm.syncroRmm",
      "position": [
        1540,
        0
      ],
      "parameters": {
        "subject": "Found duplicate Serial Numbers",
        "resource": "ticket",
        "operation": "create",
        "customerId": "",
        "additionalFields": {
          "status": "New",
          "comment": "={{ $json.comment }}\n\nTicket created automatically by n8n",
          "issueType": "Maintenance"
        }
      },
      "credentials": {
        "syncroRmmApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": false,
      "typeVersion": 1
    },
    {
      "id": "0ea4cf93-1f8a-48dd-97c6-210500ce94d1",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "weeksInterval": 2
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "417c9fd7-15ea-407c-84f1-770811d7a214",
      "name": "Exclude VMs",
      "type": "n8n-nodes-base.filter",
      "position": [
        440,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cc8ccfe7-3a59-4d82-b3c4-3efae3320046",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.properties.form_factor }}",
              "rightValue": "Virtual Server"
            },
            {
              "id": "d05e0c4a-2317-4e64-a405-6caf7eea7add",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.properties.form_factor }}",
              "rightValue": "Virtual Desktop"
            },
            {
              "id": "5e05da6c-87d8-4ac3-90f9-e03ace516589",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.asset_serial }}",
              "rightValue": "null"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "7ee944b0-62ef-4dfe-ad55-0c58b0ab10d6",
      "name": "Create labeled link field",
      "type": "n8n-nodes-base.set",
      "position": [
        660,
        0
      ],
      "parameters": {
        "include": "selected",
        "options": {
          "dotNotation": true
        },
        "assignments": {
          "assignments": [
            {
              "id": "e63832ca-4b2e-4ccd-9979-7475fcab0a37",
              "name": "link_label",
              "type": "object",
              "value": "={{ { name:  $json.name, link: $json.external_rmm_link } }}"
            }
          ]
        },
        "includeFields": "id, customer_id, asset_serial, asset_type, properties.",
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "08a96065-7b6a-4cdb-b58d-2b60401decf5",
      "name": "Format ticket comment",
      "type": "n8n-nodes-base.code",
      "position": [
        1320,
        0
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet comment = \"<p>The following list reflects duplicate serial numbers seen across Syncro assets. Review the list and merge/delete any assets which have been rebuilt or otherwise are confirmed to be duplicates.</p>\";\nfor (const item of $input.all()) {\n  comment = comment.concat(`<p>Asset Serial: ${item.json.asset_serial} (${item.json.count_id})<br />\\n`);\n  item.json.appended_link_label.forEach(link => {\n    comment = comment.concat(`* ${link.name} - ${link.link}<br />\\n`);\n  });\n  comment = comment.concat(\"</p>\\n\");\n}\n\nreturn {json: {comment: comment}};"
      },
      "typeVersion": 2
    },
    {
      "id": "c87f41f8-4105-4e27-8456-bd667a17b21f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -280
      ],
      "parameters": {
        "width": 420,
        "height": 220,
        "content": "## Creates a ticket for all duplicate assets found in Syncro.\n\nTo use:\n\n* Setup Syncro RMM credentials\n* Update customer ID on the \"Create a ticket\" node"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e191099a-5d47-419a-8488-b911932870e9",
  "connections": {
    "Exclude VMs": {
      "main": [
        [
          {
            "node": "Create labeled link field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get all assets": {
      "main": [
        [
          {
            "node": "Exclude VMs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a ticket": {
      "main": [
        []
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get all assets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format ticket comment": {
      "main": [
        [
          {
            "node": "Create a ticket",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Count by serial number": {
      "main": [
        [
          {
            "node": "Get only duplicate serials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create labeled link field": {
      "main": [
        [
          {
            "node": "Count by serial number",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get only duplicate serials": {
      "main": [
        [
          {
            "node": "Format ticket comment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}