Skip to content

Workflow Examples

The project includes a ready-to-use example workflow with two independent Webhook endpoints — one for generating random passcodes and one for sending custom passcodes. Each endpoint includes email notification.

Download example workflow: workflow-webhook-ttlock.json

What the Workflow Does

Both endpoints share the same structure:

Receive Request → Call TTLock Node → Check Result → Email Notification → Return Response
EndpointPath
Random PasscodeYour URL + /randomPasscode
Custom PasscodeYour URL + /customPasscode

Tip

Both endpoints share the same TTLock credential — activate once to use both.

Random Passcode Configuration

Quick Import

  1. Open n8n and go to the workflow list
  2. Click "..." in the top-right corner → Import from File
  3. Select the downloaded workflow-webhook-ttlock.json file (click the button above to download)
  4. After import, two complete sets of workflow nodes will appear on the canvas

Post-import Configuration

The workflow has 3 credentials that need to be replaced with your own:

CredentialPurposeSetup Guide
TTLock accountCall the TTLock nodeSee Configure Credentials
SMTP account (Email-Success node)Send success notification emailsSee Configure Email (NetEase Example) or Gmail Configuration below
SMTP account 2 (Email-Failure node)Send failure notification emailsSame as above

Configure Email (NetEase Example)

The example workflow sends email notifications on passcode generation success/failure. You need to configure SMTP email credentials first. Below is an example using NetEase 163 Mail.

Step 1: Enable SMTP Service

  1. Log in to NetEase Mail
  2. Go to SettingsPOP3/SMTP/IMAP
  3. Enable IMAP/SMTP service
  4. Click Enable, a security prompt will appear, click Continue enabling
  5. An authorization code will be displayed — copy it (you'll need it later), enter a name, and confirm

Note

The authorization code is NOT your email login password. It's the random string obtained when enabling SMTP. Keep it safe.

Step 2: Create SMTP Credential in n8n

  1. Open the n8n email node → Parameters → CredentialsAdd Credential
  2. Fill in the following information:
FieldValueDescription
Useryour-email@163.comNetEase email address
Passwordyour-auth-codeAuthorization code from SMTP setup
Hostsmtp.163.comNetEase SMTP server address
Port465SSL port
SSL/TLStrueEnable encrypted connection
  1. Click Save

Step 3: Use Credentials in Email Nodes

In the Email-Success or Email-Failure node of the example workflow:

  1. Expand the Credential dropdown
  2. Select the SMTP credential you just created
  3. Change From Email to your NetEase email address
  4. Change To Email to the notification recipient address

Configure Email (Gmail Example)

Below is an example using Google Gmail with App Password + SMTP.

Part 1: Prepare on Google Side

1. Enable 2-Step Verification (2FA)

This is a prerequisite — you cannot generate an App Password without it:

  1. Open https://myaccount.google.com/security
  2. Find Sign in to Google → Click 2-Step Verification
  3. Follow the prompts to enable it (Google Authenticator / SMS text / backup codes)

Note

You cannot generate an App Password without 2FA enabled. This is a hard requirement.

2. Generate an App Password

  1. Open https://myaccount.google.com/apppasswords
  2. If you see "No options found", you haven't enabled 2FA yet — complete the step above first
  3. Fill in:
    • Select app: Mail or Other (custom name)
    • Name: Enter n8n (for easy identification)
  4. Click Create
  5. A 16-character password will be displayed, formatted like abcd efgh ijkl mnop

Note

Copy and save it immediately! You won't be able to view it again after closing this page. Remove the spaces when entering it in n8n, i.e., use abcdefghijklmnop.

3. Confirm IMAP is Enabled

  1. Open Gmail Settings → Forwarding and POP/IMAP (https://mail.google.com/mail/u/0/#settings/fwdandpop)
  2. Find IMAP access → Select Enable IMAP
  3. Scroll down and click Save Changes

Part 2: Create SMTP Credential in n8n

  1. Open the n8n email node → Parameters → CredentialsAdd Credential
  2. Fill in the following information:
FieldValueDescription
Useryour@gmail.comYour Gmail address
Passwordyour-app-passwordThe 16-character App Password from above
Hostsmtp.gmail.comGmail SMTP server address
Port465SSL port
SSL/TLStrueEnable encrypted connection
  1. Click Save

Part 3: Use Credentials in Email Nodes

In the Email-Success or Email-Failure node of the example workflow:

  1. Expand the Credential dropdown
  2. Select the SMTP credential you just created
  3. Change From Email to your Gmail address
  4. Change To Email to the notification recipient address

Modify Email Addresses

The imported example uses placeholder email addresses — change them to your own:

  • Email-Success / Email-Success-Custom nodes: modify From Email and To Email
  • Email-Failure / Email-Failure-Custom nodes: modify From Email and To Email

Request Parameters

Tip

clientId, accessToken, and date are handled automatically by the node — no need to include these fields. See Configure Credentials.

Both endpoints share base parameters. The custom passcode endpoint additionally requires keyboardPwd and addType.

Common Parameters (Both Endpoints)

FieldTypeRequiredDescription
lockIdstringYesSmart lock ID, available via Get User Lock List API
keyboardPwdType (displayed as Passcode Type)numberNoPasscode type, default 3 (Period)
keyboardPwdName (displayed as Passcode Name)stringNoPasscode name
startDatestringYesPasscode effective time
endDatestringNoPasscode expiry time

Additional Parameters for Custom Passcode Endpoint

FieldTypeRequiredDescription
keyboardPwd (displayed as Passcode)stringYesPasscode content to transmit, e.g., 5809371
addType (displayed as Add Method)numberNoAdd method, default 1 (Bluetooth). See docs for details

For full parameter details: TTLock Open Platform Docs - Create Random Passcode / Add Custom Passcode

Usage Examples

Create Random Passcode

bash
curl -X POST http://your-n8n-url/randomPasscode \
  -H "Content-Type: application/json" \
  -d '{
    "lockId": "your-lock-id",
    "keyboardPwdType": 3,
    "keyboardPwdName": "Guest Passcode",
    "startDate": "2026-05-07 09:00:00",
    "endDate": "2026-05-07 18:00:00"
  }'

Create Custom Passcode

bash
curl -X POST http://your-n8n-url/customPasscode \
  -H "Content-Type: application/json" \
  -d '{
    "lockId": "your-lock-id",
    "keyboardPwd": "5809371",
    "keyboardPwdType": 3,
    "keyboardPwdName": "Custom Passcode",
    "startDate": "2026-05-07 09:00:00",
    "endDate": "2026-05-07 18:00:00",
    "addType": 1
  }'

Response

Random Passcode

json
{
  "keyboardPwd": "73691670",
  "keyboardPwdId": 7906873
}

Custom Passcode

json
{
  "keyboardPwdId": 7906873
}

Node Description

Both endpoint sets have identical node structures — only names and configurations differ:

NodeTypeRole
Webhook / Webhook-Customn8n built-inReceive POST requests using Respond to Webhook mode
TTLock / TTLock-CustomTTLock NodeExtract params from request body, call corresponding API, Continue On Fail enabled
Check Result / Check Result-Customn8n built-inCheck if errcode is empty to distinguish success/failure branches
Email-Success / Email-Success-Customn8n built-inSend HTML email with passcode on success (blue theme for random, green theme for custom)
Email-Failure / Email-Failure-Customn8n built-inSend HTML email with error info on failure (red theme)
Respond / Respond-Customn8n built-inReturn TTLock raw response as JSON

Customization

You can edit the imported workflow directly on the n8n canvas:

  • Webhook path: Modify the Path field in the corresponding Webhook node
  • Default passcode type: Change the expression in the corresponding TTLock node's keyboardPwdType field
  • Email templates: Edit styles and content in the corresponding email node's HTML field
  • Skip email: If you don't need email notifications, delete the email nodes directly and connect the IF node output to the Respond node