# n8n

1. **步骤 1（获取令牌）：** 将应用 ID 和密钥发送到 `/oauth2/token` 以获取临时 `access_token`。
2. **步骤 2（运行任务）：** 将令牌放入请求头中，并构建包含**字符串化 JSON** 的参数以触发云手机任务。


## 前提条件

开始之前，请确保您已准备好以下信息：

1. **API 凭证**（从 [MoreLogin 控制面板](https://id.morelogin.com/) -> API 管理](https://id.morelogin.com/) 获取）：


* `应用 ID`（即 client_id）
* `密钥`（即 client_secret）


[如何获取授权？](https://guide.morelogin.com/api-reference/open-api/open-api/authorization/paths/~1oauth2~1token/post)

1. **资源 ID**（从云手机列表和模板市场获取）：


* `云手机 ID`（仅限数字）
* `模板 ID`（仅限数字）


[如何获取授权？](https://guide.morelogin.com/api-reference/open-api/open-api/authorization/paths/~1oauth2~1token/post)

[如何获取？](https://guide.morelogin.com/api-reference/open-api/open-api/cloud-phoneschedules-management/paths/~1cloudphone~1rpa~1oncetask~1save/post)

## 一键工作流导入

为了简化配置，我们为您打包了一个完整的 n8n 双节点工作流。您无需手动处理令牌传递和复杂的 JSON 转义。

**只需复制以下 JSON 代码并将其粘贴（Ctrl+V）到 n8n 画布中：**

```json
{

"nodes": [

{

"parameters": {

"method": "POST",

"url": "https://api.morelogin.com/oauth2/token",

"sendBody": true,

"contentType": "json",

"bodyParameters": {

"parameters": [

{

"name": "client_id",

"value": "YOUR_APP_ID_HERE"

},

{

"name": "client_secret",

"value": "YOUR_SECRET_KEY_HERE"

},

{

"name": "grant_type",

"value": "client_credentials"

}

]

},

"options": {}

},

"id": "step_1_auth",

"name": "步骤 1：获取令牌",

"type": "n8n-nodes-base.httpRequest",

"typeVersion": 4.1,

"position": [

460,

300

]

},

{

"parameters": {

"method": "POST",

"url": "https://api.morelogin.com/cloudphone/rpa/onceTask/save",

"sendHeaders": true,

"headerParameters": {

"parameters": [

{

"name": "Authorization",

"value": "={{ 'Bearer ' + $json.data.access_token }}"

}

]

},

"sendBody": true,

"contentType": "json",

"bodyParameters": {

"parameters": [

{

"name": "cloudPhoneId",

"value": 1234567890

},

{

"name": "templateId",

"value": 1678347487160256

},

{

"name": "scheduleName",

"value": "n8n-Auto-Task"

},

{

"name": "description",

"value": "通过 n8n 触发"

},

{

"name": "templateParameter",

"value": "={{ JSON.stringify({\n \"Video Caption\": \"My Automation Video\",\n \"AI Label\": true,\n \"Product Id\": 1001,\n \"Get Leads\": false,\n \"Comment\": \"Great content!\"\n}) }}"

}
]

},

"options": {}

},

"id": "step_2_run_task",

"name": "步骤 2：运行任务",

"type": "n8n-nodes-base.httpRequest",

"typeVersion": 4.1,

"position": [

680,

300

],

"dependencies": {

"nodes": [

{

"node": "步骤 1：获取令牌",

"type": "main",

"index": 0

}
]

}
}

],

"connections": {

"步骤 1：获取令牌": {

"main": [

[

{

"node": "步骤 2：运行任务",

"type": "main",

"index": 0

}
]

]

}
}
}```
```