{
  "updatedAt": "2025-05-13T05:39:53.000Z",
  "createdAt": "2025-05-13T05:33:13.555Z",
  "id": "MV1mljkA6IZjmR1u",
  "name": "Lark Base Authorize and Call API Template",
  "description": null,
  "active": false,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "https://open.larksuite.com/open-apis/auth/v3/app_access_token/internal",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n\"app_id\" : \"APP_ID_CUA_BAN\",\n\"app_secret\" : \"APP_SECRET_CUA_BAN\" \n}",
        "options": {}
      },
      "id": "d967bf4f-9768-46ec-b179-4258952d90ad",
      "name": "GET access TOken",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        20,
        320
      ]
    },
    {
      "parameters": {
        "path": "larksuit-auth",
        "options": {}
      },
      "id": "f8a05143-ae15-420d-a394-e46fd6d0d1ec",
      "name": "Webhook1",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        -180,
        320
      ],
      "webhookId": "70d96ffa-49c9-4db6-a252-a5f3e28edd38",
      "notesInFlow": false
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://open.larksuite.com/open-apis/authen/v1/access_token",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.app_access_token }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json; charset=utf-8"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "grant_type",
              "value": "authorization_code"
            },
            {
              "name": "code",
              "value": "={{ $('Webhook1').item.json.query.code }}"
            }
          ]
        },
        "options": {}
      },
      "id": "5a2a25ec-5b6e-4377-a938-c0476e63c36f",
      "name": "get user access token",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "options": {}
      },
      "id": "edefb992-e003-4ee1-b816-f4ab536089b8",
      "name": "Convert to/from binary data",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        580,
        300
      ]
    },
    {
      "parameters": {
        "content": "## Gọi cấp quyền (https://p4b1xibkuek.sg.larksuite.com/drive/home/)\n\n[link authorize](https://open.larksuite.com/open-apis/authen/v1/index?redirect_uri=https://n8n.mecode.pro/webhook/larksuit-auth&app_id=cli_a5fdab9cfdf8902f)\n\n"
      },
      "id": "732ca843-8d4f-41a5-af16-7d3038e4708d",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -320,
        220
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 9
            }
          ]
        }
      },
      "id": "d02c070a-b851-4a61-a05b-8120d055f2b6",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        -220,
        -20
      ]
    },
    {
      "parameters": {
        "fileSelector": "user_token_larksuit.txt"
      },
      "id": "572ac4f0-6fd5-4cc7-b6d3-4fb8d3e16510",
      "name": "Read Binary Files1",
      "type": "n8n-nodes-base.readBinaryFiles",
      "typeVersion": 1,
      "position": [
        200,
        -20
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "3cc43eab-69c3-4795-882d-e68ebe42c2fa",
      "name": "Convert to/from binary data2",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        460,
        -20
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://open.larksuite.com/open-apis/authen/v1/refresh_access_token",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "=Authorization",
              "value": "=Bearer {{ $json.application_token }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json; charset=utf-8"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "grant_type",
              "value": "refresh_token"
            },
            {
              "name": "refresh_token",
              "value": "={{ $json.data.refresh_token }}"
            }
          ]
        },
        "options": {}
      },
      "id": "7e816922-bf4b-48dc-b5cd-8b5521e6093b",
      "name": "refesh token",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        700,
        -20
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "options": {}
      },
      "id": "ab7520c7-1963-4972-a2a2-2fd8f4ceddf2",
      "name": "Convert to/from binary data3",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        1380,
        -20
      ]
    },
    {
      "parameters": {
        "fileName": "user_token_larksuit.txt",
        "options": {}
      },
      "id": "6a260911-e295-4b0d-84f9-ab3875b8f1cf",
      "name": "Write Binary File1",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        1540,
        120
      ]
    },
    {
      "parameters": {
        "content": "## refesh Lark token\n"
      },
      "id": "e57653a0-ef0d-4ca5-9c29-202aca894217",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -340,
        -100
      ]
    },
    {
      "parameters": {
        "chatId": "5444173779",
        "text": "=Refresh token moi: {{JSON.stringify($json)}}\n- Tu data\n{{ JSON.stringify($('Convert to/from binary data2').item.json) }}",
        "additionalFields": {}
      },
      "id": "8b084ffd-c357-4022-9be1-9193fd028e8d",
      "name": "Telegram2",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.1,
      "position": [
        1240,
        200
      ],
      "webhookId": "39c76977-0e91-441d-bfe3-eff1b475c06f",
      "credentials": {
        "telegramApi": {
          "id": "eHvjvLSJZ09HqYpi",
          "name": "Telegram account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "2ec83fed-a9d9-4d68-b964-d521762e6369",
              "leftValue": "={{ $json.data.access_token }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "5fa44283-4470-4b81-8e5e-d794cddce935",
      "name": "If co token",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        920,
        -20
      ]
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "=https://open.larksuite.com/open-apis/bitable/v1/apps/{{ $('Loop Over Items2').item.json.base_id }}/tables/{{  $('Loop Over Items2').item.json.table_id }}/records/{{ $json.itemData.fields.LarkId }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('token binary to text').item.json.data.access_token }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"fields\": {{JSON.stringify($json.itemData.fields)}} }",
        "options": {}
      },
      "id": "cff1a212-90f8-40e6-b54a-a8728a7e0a27",
      "name": "update record1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        320,
        -500
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://open.larksuite.com/open-apis/bitable/v1/apps/{BASE_ID}/tables/{TABLE_ID}/records",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {TOKEN}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"fields\": {{JSON.stringify($('Loop Over Items2').item.json.itemData[\"fields\"])}} }",
        "options": {}
      },
      "id": "996c5bb6-622a-403a-91bc-5a6607ef7d8d",
      "name": "tao record1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        80,
        -500
      ]
    },
    {
      "parameters": {
        "url": "= {{ $json.itemData.fields.LarkId ? `https://open.larksuite.com/open-apis/bitable/v1/apps/${$json.base_id}/tables/${$json.table_id}/records?filter=CurrentValue.[LarkId]=\"${$json.itemData.fields.LarkId}\"` : `https://open.larksuite.com/open-apis/bitable/v1/apps/${$json.base_id}/tables/${$json.table_id}/records?filter=CurrentValue.[${encodeURI(\"Mã ĐH\")}]=\"${$json.itemData.fields['Mã ĐH']}\"`}}\n",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.data.access_token }}"
            }
          ]
        },
        "options": {}
      },
      "id": "84f6f00a-1297-40bc-b93f-53f63892d4c1",
      "name": "Find",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        560,
        -500
      ]
    },
    {
      "parameters": {
        "content": "## gọi API\nĐọc token từ file user_token_larksuit.txt\nTruyền vào node API\n"
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -120,
        -600
      ],
      "id": "a8ed6f53-b2c1-4fb4-943f-c5ce69e99238",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "app_access_token",
              "stringValue": "FILL_KEY_CUA_BAN"
            }
          ]
        },
        "options": {}
      },
      "id": "6ca109f9-192f-4d6a-a5e7-1f23017a2126",
      "name": "set_app_token",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.1,
      "position": [
        0,
        -20
      ]
    },
    {
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "application_token",
              "stringValue": "={{ $('Convert to/from binary data2').item.json.application_token }}"
            }
          ]
        },
        "options": {}
      },
      "id": "192eea69-7e2a-41bf-8817-a36458856191",
      "name": "set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.1,
      "position": [
        1200,
        -20
      ]
    },
    {
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "application_token",
              "stringValue": "={{ $('GET access TOken').item.json.app_access_token }}"
            }
          ]
        },
        "options": {}
      },
      "id": "b78f0f29-ceef-48fd-8bee-ad9585878ee7",
      "name": "set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.1,
      "position": [
        400,
        300
      ]
    },
    {
      "parameters": {
        "fileName": "user_token_larksuit.txt",
        "options": {}
      },
      "id": "2be96816-434a-44db-895b-8938077bd4e9",
      "name": "luu_token_file",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        780,
        300
      ]
    }
  ],
  "connections": {
    "GET access TOken": {
      "main": [
        [
          {
            "node": "get user access token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook1": {
      "main": [
        [
          {
            "node": "GET access TOken",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get user access token": {
      "main": [
        [
          {
            "node": "set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to/from binary data": {
      "main": [
        [
          {
            "node": "luu_token_file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "set_app_token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Binary Files1": {
      "main": [
        [
          {
            "node": "Convert to/from binary data2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to/from binary data2": {
      "main": [
        [
          {
            "node": "refesh token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "refesh token": {
      "main": [
        [
          {
            "node": "If co token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to/from binary data3": {
      "main": [
        [
          {
            "node": "Write Binary File1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If co token": {
      "main": [
        [
          {
            "node": "set",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Telegram2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "set_app_token": {
      "main": [
        [
          {
            "node": "Read Binary Files1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "set": {
      "main": [
        [
          {
            "node": "Convert to/from binary data3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "set1": {
      "main": [
        [
          {
            "node": "Convert to/from binary data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": null,
  "pinData": {},
  "versionId": "cb9d7ab9-ff26-4d13-8561-357e12b4f0bf",
  "activeVersionId": null,
  "versionCounter": 1,
  "triggerCount": 0,
  "shared": [
    {
      "updatedAt": "2025-05-13T05:33:13.566Z",
      "createdAt": "2025-05-13T05:33:13.566Z",
      "role": "workflow:owner",
      "workflowId": "MV1mljkA6IZjmR1u",
      "projectId": "Nlp7kXCVcAfb0cmG",
      "project": {
        "updatedAt": "2024-07-25T03:06:26.102Z",
        "createdAt": "2024-07-25T03:06:26.102Z",
        "id": "Nlp7kXCVcAfb0cmG",
        "name": "Bình Đặng <dangngocbinh.dnb@gmail.com>",
        "type": "personal",
        "icon": null,
        "description": null,
        "creatorId": "92f1ca82-c19e-4a7d-8458-93b65f67f4c7"
      }
    }
  ],
  "tags": [
    {
      "updatedAt": "2024-10-04T03:03:40.628Z",
      "createdAt": "2024-10-04T03:03:40.628Z",
      "id": "MW10UcI4NI01thiG",
      "name": "share"
    }
  ],
  "activeVersion": null
}