{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/zh/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"通过 HTTP 调用模板","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"通过-http-调用模板","__idx":0},"children":["通过 HTTP 调用模板"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"1-获取授权oauth2-令牌","__idx":1},"children":["1. 获取授权（OAuth2 令牌）"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["在调用任何功能性 API 之前，您必须先使用您的凭据交换 ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["JWT 访问令牌"]},"。"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["端点："]}," ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST https://api.morelogin.com/oauth2/token"]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["官方文档："]}," ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://guide.morelogin.com/api-reference/open-api/open-api/authorization/paths/~1oauth2~1token/post"},"children":["授权路径"]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"请求curl","__idx":2},"children":["请求（cURL）"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl -i -X POST \\\n  https://api.morelogin.com/oauth2/token \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"client_id\": 1672940217990530,\n    \"client_secret\": \"your_client_secret\",\n    \"grant_type\": \"client_credentials\"\n  }'\n```### 回复示例\n\n```json\n{\n    \"code\": 0,\n    \"data\": {\n        \"access_token\": \"eyJhbGciOiJIUzI1NiIsIn...\",\n        \"token_type\": \"Bearer\",\n        \"expires_in\": 3600\n    }\n}\n```---\n\n## 2. 执行云手机模板\n\n使用步骤 1 中获取的 access_token 来触发特定的 RPA 模板。\n\n* **端点：** `POST https://api.morelogin.com/cloudphone/rpa/onceTask/save`\n\n* **官方文档：** [执行计划路径](https://guide.morelogin.com/api-reference/open-api/open-api/cloud-phoneschedules-management/paths/~1cloudphone~1rpa~1oncetask~1save/post)\n\n### 请求 (cURL)\n\n```bash\ncurl -i -X POST \\\n  https://api.morelogin.com/cloudphone/rpa/onceTask/save \\\n  -H 'Authorization: Bearer <YOUR_JWT_HERE>' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"cloudPhoneId\": 16783319661123,\n    \"scheduleName\": \"test_automation\",\n    \"templateId\": 1678347487160256,\n    \"templateParameter\": \"{\\\"Video Caption\\\": \\\"Hello World\\\", \\\"AI Label\\\": true}\",\n    \"description\": \"schedule description\"\n  }'\n```---\n\n## 3. 参数详解\n\n### 如何获取 ID？\n\n* **Authorization：** 通过 `/oauth2/token` 端点获取。\n\n* **cloudPhoneId：** 在 MoreLogin 云手机控制面板中找到（数字 ID）。\n\n* **templateId：** 在自动化模板市场或个人模板列表中找到。\n\n### 理解 templateParameter\n\n这是一个字符串化的 JSON 对象。您必须根据模板的要求定义键，然后将其转义为字符串。\n\n**模板定义示例：**\n\n```json\n{\n    \"Video Caption\": \"string\",\n    \"AI Label\": \"boolean\",\n    \"Product Id\": \"number\",\n    \"Get Leads\": \"boolean\",\n    \"Comment\": \"string\"\n}\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["如何在请求中映射："]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["要为上述定义传递值，您的 templateParameter 值应如下所示："]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n    \"templateParameter\": \"{\\\"Video Caption\\\": \\\"My Title\\\", \\\"AI Label\\\": true, \\\"Product Id\\\": 12345}\"\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"4-错误处理","__idx":3},"children":["4. 错误处理"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["| 状态 | 可能原因 |"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["| ---------------- | ------------------------------------------------------------ |"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["| 401 未授权 | 令牌过期或客户端凭据无效。 |"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["| 400 错误请求 | cloudPhoneId 无效或 templateParameter 中的 JSON 格式错误。 |"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["| 404 未找到 | templateId 不存在。 |"]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"python-快速入门","__idx":4},"children":["Python 快速入门"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"import requests\nimport json\n\ndef run_morelogin_task():\n    # 1. Auth\n    auth_res = requests.post(\n        \"https://api.morelogin.com/oauth2/token\",\n        json={\n            \"client_id\": 1672940217990530,\n            \"client_secret\": \"your_secret\",\n            \"grant_type\": \"client_credentials\"\n        }\n    )\n    token = auth_res.json()['data']['access_token']\n\n    # 2. Execute\n    task_payload = {\n        \"cloudPhoneId\": 16783319661123,\n        \"templateId\": 1678347487160256,\n        \"templateParameter\": json.dumps({\n            \"Video Caption\": \"My Post\",\n            \"AI Label\": True\n        })\n    }\n    \n    headers = {\"Authorization\": f\"Bearer {token}\"}\n    response = requests.post(\n        \"https://api.morelogin.com/cloudphone/rpa/onceTask/save\",\n        json=task_payload,\n        headers=headers\n    )\n    return response.json()\n\nprint(run_morelogin_task())\n","lang":"python"},"children":[]}]},"headings":[{"value":"通过 HTTP 调用模板","id":"通过-http-调用模板","depth":1},{"value":"1. 获取授权（OAuth2 令牌）","id":"1-获取授权oauth2-令牌","depth":2},{"value":"请求（cURL）","id":"请求curl","depth":3},{"value":"4. 错误处理","id":"4-错误处理","depth":2},{"value":"Python 快速入门","id":"python-快速入门","depth":2}],"frontmatter":{"seo":{"title":"通过 HTTP 调用模板"}},"lastModified":"2026-06-10T11:47:34.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/zh/rparobotic-process-automation/04-integration/call-template-via-http","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}