{
  "name": "TTLock_Complete_Workflow",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "randomPasscode",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "84f7a2fb-77f8-486a-8076-b9b914ea222d",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        720,
        112
      ],
      "webhookId": "bafbac5c-3fef-410c-b415-9eac6046c113"
    },
    {
      "parameters": {
        "lockId": "={{ $json.body.lockId }}",
        "keyboardPwdType": "={{ $json.body.keyboardPwdType || 3 }}",
        "keyboardPwdName": "={{ $json.body.keyboardPwdName || '' }}",
        "startDate": "={{ $json.body.startDate }}",
        "endDate": "={{ $json.body.endDate || '' }}"
      },
      "id": "0b1db3af-fd92-4a5f-879c-e5a18a6d54fd",
      "name": "TTLock",
      "type": "n8n-nodes-ttlock.sciener",
      "typeVersion": 1,
      "position": [
        976,
        112
      ],
      "credentials": {
        "scienerApi": {
          "id": "G336DW9N6JQczOqK",
          "name": "TTLock account"
        }
      },
      "continueOnFail": true
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.errcode }}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "id": "423a2d85-ed7f-4bdd-917f-b19d0a376dbb",
      "name": "Check Result",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1248,
        112
      ]
    },
    {
      "parameters": {
        "fromEmail": "",
        "toEmail": "=",
        "subject": "=TTLock Password Created Successfully",
        "html": "=<div style=\"background-color: #f6f8fa; padding: 40px 20px; font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;\">\n  <div style=\"max-width: 460px; margin: 0 auto; background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 20px rgba(0,0,0,0.08);\">\n    <!-- Header Bar -->\n    <div style=\"background-color: #3b82f6; padding: 24px; text-align: center;\">\n      <h2 style=\"margin: 0; color: #ffffff; font-size: 20px; font-weight: 600; letter-spacing: 1px;\">Password Created Successfully</h2>\n    </div>\n\n    <!-- Content Area -->\n    <div style=\"padding: 32px 24px;\">\n      <!-- Password Display -->\n      <div style=\"background-color: #f8fafc; border: 1px solid #f1f5f9; border-radius: 12px; padding: 30px; text-align: center; margin-bottom: 20px;\">\n        <div style=\"font-size: 14px; color: #64748b; margin-bottom: 8px;\">Unlock Password Ready</div>\n        <div style=\"font-size: 36px; font-weight: 700; color: #1e293b; letter-spacing: 4px; font-family: 'Consolas', monospace;\">\n          {{ $node[\"TTLock\"].json[\"keyboardPwd\"] }}\n        </div>\n      </div>\n\n      <!-- Details -->\n      <table width=\"100%\" cellpadding=\"16\" cellspacing=\"0\" style=\"border: 1px solid #f1f5f9; border-radius: 12px; background-color: #ffffff;\">\n        <tr>\n          <td style=\"font-size: 14px; color: #64748b;\">Password ID</td>\n          <td style=\"font-size: 14px; color: #1e293b; font-family: monospace; text-align: right;\">{{ $node[\"TTLock\"].json[\"keyboardPwdId\"] }}</td>\n        </tr>\n      </table>\n\n      <div style=\"margin-top: 32px; text-align: center;\">\n      </div>\n    </div>\n  </div>\n</div>",
        "options": {}
      },
      "id": "6ef14cc0-8bff-42aa-9672-3289016a7223",
      "name": "Email - Success",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1536,
        -16
      ],
      "webhookId": "0c5b1e50-9569-49c7-b8c4-c7879568ba13",
      "credentials": {
        "smtp": {
          "id": "mjxpQra8gwxAjRNK",
          "name": "SMTP account"
        }
      }
    },
    {
      "parameters": {
        "fromEmail": "",
        "toEmail": "=",
        "subject": "=TTLock Password Generation Failed",
        "html": "=<div style=\"background-color: #fff5f5; padding: 40px 20px; font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;\">\n  <div style=\"max-width: 460px; margin: 0 auto; background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 20px rgba(0,0,0,0.08); border: 1px solid #feb2b2;\">\n    <!-- Warning Header -->\n    <div style=\"background-color: #ef4444; padding: 24px; text-align: center;\">\n      <h2 style=\"margin: 0; color: #ffffff; font-size: 20px; font-weight: 600; letter-spacing: 1px;\">Password Generation Failed</h2>\n    </div>\n\n    <!-- Content Area -->\n    <div style=\"padding: 32px 24px;\">\n      <!-- Error Description -->\n      <div style=\"background-color: #fffaf0; border-left: 4px solid #f59e0b; padding: 20px; border-radius: 4px; margin-bottom: 20px;\">\n        <div style=\"font-size: 14px; font-weight: 600; color: #9a3412; margin-bottom: 4px;\">Error Reason</div>\n        <div style=\"font-size: 14px; color: #7c2d12; line-height: 1.6;\">\n          {{ $node[\"TTLock\"].json[\"errmsg\"] ||  $node[\"TTLock\"].json[\"description\"] || 'Server response timed out, please try again later' }}\n        </div>\n      </div>\n\n      <!-- Error Code -->\n      <table width=\"100%\" cellpadding=\"16\" cellspacing=\"0\" style=\"border: 1px solid #f1f5f9; border-radius: 12px; background-color: #ffffff;\">\n        <tr>\n          <td style=\"font-size: 14px; color: #64748b;\">Error Code</td>\n          <td style=\"font-size: 14px; color: #ef4444; font-weight: 600; font-family: monospace; text-align: right;\">{{ $node[\"TTLock\"].json[\"errcode\"] }}</td>\n        </tr>\n      </table>\n\n    </div>\n  </div>\n</div>",
        "options": {}
      },
      "id": "c1dbffaf-62d1-45b0-82db-96bd9d5aae6a",
      "name": "Email - Failure",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1536,
        240
      ],
      "webhookId": "19ed9948-b3c6-440b-8ff5-0c4bba105551",
      "credentials": {
        "smtp": {
          "id": "mjxpQra8gwxAjRNK",
          "name": "SMTP account"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $('TTLock').item.json }}",
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        }
      },
      "id": "540eeced-0bde-45a6-aaf4-ddd0d6120cd3",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1920,
        64
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "customPasscode",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "f05620c8-b17d-408c-a0ba-5b6eaf5a82b4",
      "name": "Webhook-Custom",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        720,
        560
      ],
      "webhookId": "c2d3e4f5-6789-abcd-ef01-234567890abc"
    },
    {
      "parameters": {
        "operation": "custom",
        "customLockId": "={{ $json.body.lockId }}",
        "customKeyboardPwd": "={{ $json.body.keyboardPwd }}",
        "customKeyboardPwdName": "={{ $json.body.keyboardPwdName || '' }}",
        "customKeyboardPwdType": "={{ $json.body.keyboardPwdType || 3 }}",
        "customStartDate": "={{ $json.body.startDate || '' }}",
        "customEndDate": "={{ $json.body.endDate || '' }}",
        "customAddType": "={{ $json.body.addType || '1' }}"
      },
      "id": "a708919a-f0ee-4d45-a092-7d992d032326",
      "name": "TTLock-Custom",
      "type": "n8n-nodes-ttlock.sciener",
      "typeVersion": 1,
      "position": [
        976,
        560
      ],
      "credentials": {
        "scienerApi": {
          "id": "G336DW9N6JQczOqK",
          "name": "TTLock account"
        }
      },
      "continueOnFail": true
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.errcode }}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "id": "ced5edec-61a9-4efa-b89c-e55abf28e0d4",
      "name": "Check Result - Custom",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1248,
        560
      ]
    },
    {
      "parameters": {
        "toEmail": "=",
        "subject": "=TTLock Custom Password Set Successfully",
        "html": "=<div style=\"background-color: #f6f8fa; padding: 40px 20px; font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;\">\n  <div style=\"max-width: 460px; margin: 0 auto; background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 20px rgba(0,0,0,0.08);\">\n    <div style=\"background-color: #10b981; padding: 24px; text-align: center;\">\n      <h2 style=\"margin: 0; color: #ffffff; font-size: 20px; font-weight: 600; letter-spacing: 1px;\">Custom Password Set Successfully</h2>\n    </div>\n\n    <div style=\"padding: 32px 24px;\">\n      <div style=\"background-color: #f8fafc; border: 1px solid #f1f5f9; border-radius: 12px; padding: 30px; text-align: center; margin-bottom: 20px;\">\n        <div style=\"font-size: 14px; color: #64748b; margin-bottom: 8px;\">Custom Unlock Password</div>\n        <div style=\"font-size: 36px; font-weight: 700; color: #1e293b; letter-spacing: 4px; font-family: 'Consolas', monospace;\">\n         {{ $('Webhook-Custom').item.json.body.keyboardPwd }}\n        </div>\n      </div>\n\n      <table width=\"100%\" cellpadding=\"16\" cellspacing=\"0\" style=\"border: 1px solid #f1f5f9; border-radius: 12px; background-color: #ffffff;\">\n        <tr>\n          <td style=\"font-size: 14px; color: #64748b;\">Password ID</td>\n          <td style=\"font-size: 14px; color: #1e293b; font-family: monospace; text-align: right;\">{{ $json.keyboardPwdId }}</td>\n        </tr>\n      </table>\n\n      <div style=\"margin-top: 32px; text-align: center;\">\n      </div>\n    </div>\n  </div>\n</div>",
        "options": {}
      },
      "id": "168dcfc0-944e-487f-9aba-45e09b89b9be",
      "name": "Email - Success - Custom",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1536,
        432
      ],
      "webhookId": "37d88411-3076-484a-806c-19778b854079",
      "credentials": {
        "smtp": {
          "id": "mjxpQra8gwxAjRNK",
          "name": "SMTP account"
        }
      }
    },
    {
      "parameters": {
        "subject": "=TTLock Custom Password Set Failed",
        "html": "=<div style=\"background-color: #fff5f5; padding: 40px 20px; font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;\">\n  <div style=\"max-width: 460px; margin: 0 auto; background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 20px rgba(0,0,0,0.08); border: 1px solid #feb2b2;\">\n    <div style=\"background-color: #ef4444; padding: 24px; text-align: center;\">\n      <h2 style=\"margin: 0; color: #ffffff; font-size: 20px; font-weight: 600; letter-spacing: 1px;\">Custom Password Set Failed</h2>\n    </div>\n\n    <div style=\"padding: 32px 24px;\">\n      <div style=\"background-color: #fffaf0; border-left: 4px solid #f59e0b; padding: 20px; border-radius: 4px; margin-bottom: 20px;\">\n        <div style=\"font-size: 14px; font-weight: 600; color: #9a3412; margin-bottom: 4px;\">Error Reason</div>\n        <div style=\"font-size: 14px; color: #7c2d12; line-height: 1.6;\">\n          {{ $json.errmsg ||  $json.description  || 'Server response timed out, please try again later' }}\n        </div>\n      </div>\n\n      <table width=\"100%\" cellpadding=\"16\" cellspacing=\"0\" style=\"border: 1px solid #f1f5f9; border-radius: 12px; background-color: #ffffff;\">\n        <tr>\n          <td style=\"font-size: 14px; color: #64748b;\">Error Code</td>\n          <td style=\"font-size: 14px; color: #ef4444; font-weight: 600; font-family: monospace; text-align: right;\">{{ $json.errcode }}</td>\n        </tr>\n      </table>\n\n    </div>\n  </div>\n</div>",
        "options": {}
      },
      "id": "a7d1f005-f106-4486-9239-886ec96a448c",
      "name": "Email - Failure - Custom",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1536,
        688
      ],
      "webhookId": "4b53b08d-dd3a-4204-9906-63152c04e3bd",
      "credentials": {
        "smtp": {
          "id": "mjxpQra8gwxAjRNK",
          "name": "SMTP account"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $('TTLock-Custom').item.json }}",
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        }
      },
      "id": "7d46db22-e971-45e7-9d4a-b87e2eb2c6ac",
      "name": "Respond-Custom",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1920,
        512
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "TTLock",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "TTLock": {
      "main": [
        [
          {
            "node": "Check Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Result": {
      "main": [
        [
          {
            "node": "Email - Success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email - Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email - Success": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email - Failure": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook-Custom": {
      "main": [
        [
          {
            "node": "TTLock-Custom",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "TTLock-Custom": {
      "main": [
        [
          {
            "node": "Check Result - Custom",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Result - Custom": {
      "main": [
        [
          {
            "node": "Email - Success - Custom",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email - Failure - Custom",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email - Success - Custom": {
      "main": [
        [
          {
            "node": "Respond-Custom",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email - Failure - Custom": {
      "main": [
        [
          {
            "node": "Respond-Custom",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "2d2fb805-f5e2-4d93-85b5-705b4cc23491",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "cd2aba1c94d7da1f7d3a12a537ebf3e901f03aa43ab07cf9dce252d618710a52"
  },
  "id": "NgJ1HKqMFu7Dig5U",
  "tags": []
}