{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/vi/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Mẫu gọi API qua 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":"mẫu-gọi-api-qua-http","__idx":0},"children":["Mẫu gọi API qua HTTP"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"1-lấy-thông-tin-xác-thực-mã-thông-báo-oauth2","__idx":1},"children":["1. Lấy thông tin xác thực (Mã thông báo OAuth2)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Trước khi gọi bất kỳ API chức năng nào, bạn phải đổi thông tin đăng nhập của mình lấy ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Mã thông báo truy cập JWT"]},"."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Điểm cuối:"]}," ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST https://api.morelogin.com/oauth2/token"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Tài liệu chính thức:"]}," ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://guide.morelogin.com/api-reference/open-api/open-api/authorization/paths/~1oauth2~1token/post"},"children":["Đường dẫn xác thực"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"yêu-cầu-curl","__idx":2},"children":["Yêu cầu (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","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"ví-dụ-về-phản-hồi","__idx":3},"children":["Ví dụ về phản hồi"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n    \"code\": 0,\n    \"data\": {\n        \"access_token\": \"eyJhbGciOiJIUzI1NiIsIn...\",\n        \"token_type\": \"Bearer\",\n        \"expires_in\": 3600\n    }\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"2-thực-thi-mẫu-cloud-phone","__idx":4},"children":["2. Thực thi mẫu Cloud Phone"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Sử dụng access_token nhận được từ Bước 1 để kích hoạt một mẫu RPA cụ thể."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Điểm cuối:"]}," ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST https://api.morelogin.com/cloudphone/rpa/onceTask/save"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Tài liệu chính thức:"]}," ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://guide.morelogin.com/api-reference/open-api/open-api/cloud-phoneschedules-management/paths/~1cloudphone~1rpa~1oncetask~1save/post"},"children":["Đường dẫn thực thi lịch trình"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"yêu-cầu-curl-1","__idx":5},"children":["Yêu cầu (cURL)"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl -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","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"3-phân-tích-tham-số","__idx":6},"children":["3. Phân tích tham số"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"cách-lấy-id","__idx":7},"children":["Cách lấy ID?"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Authorization:"]}," Lấy được thông qua điểm cuối ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/oauth2/token"]},"."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["cloudPhoneId:"]}," Tìm thấy trong bảng điều khiển Cloud Phone của MoreLogin (ID số)."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["templateId:"]}," Tìm thấy trong thị trường Mẫu tự động hóa hoặc danh sách mẫu cá nhân."]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"hiểu-về-templateparameter","__idx":8},"children":["Hiểu về templateParameter"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Đây là một đối tượng JSON được chuyển đổi thành chuỗi. Bạn phải xác định các khóa dựa trên yêu cầu của mẫu và sau đó mã hóa chúng thành chuỗi."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Ví dụ về định nghĩa mẫu:"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["**```json"," ","{"," ","\"Video Caption\": \"string\","," ","\"AI Label\": \"boolean\","," ","\"Product Id\": \"number\","," ","\"Get Leads\": \"boolean\","," ","\"Comment\": \"string\""," ","}"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"\n**Cách ánh xạ nó trong yêu cầu của bạn:**\n\nĐể truyền các giá trị cho định nghĩa ở trên, giá trị templateParameter của bạn sẽ có dạng như sau:\n\n```json\n{\n    \"templateParameter\": \"{\\\"Video Caption\\\": \\\"My Title\\\", \\\"AI Label\\\": true, \\\"Product Id\\\": 12345}\"\n}\n"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"4-xử-lý-lỗi","__idx":9},"children":["4. Xử lý lỗi"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["| Trạng thái | Lý do có thể |"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["| ---------------- | ------------------------------------------------------------ |"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["| 401 Không được phép | Mã thông báo hết hạn hoặc thông tin đăng nhập của máy khách không hợp lệ. |"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["| 400 Yêu cầu không hợp lệ | cloudPhoneId không hợp lệ hoặc JSON bị lỗi trong templateParameter. |"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["| 404 Không tìm thấy | templateId không tồn tại. |"]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"hướng-dẫn-nhanh-python","__idx":10},"children":["Hướng dẫn nhanh 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":"Mẫu gọi API qua HTTP","id":"mẫu-gọi-api-qua-http","depth":1},{"value":"1. Lấy thông tin xác thực (Mã thông báo OAuth2)","id":"1-lấy-thông-tin-xác-thực-mã-thông-báo-oauth2","depth":2},{"value":"Yêu cầu (cURL)","id":"yêu-cầu-curl","depth":3},{"value":"Ví dụ về phản hồi","id":"ví-dụ-về-phản-hồi","depth":3},{"value":"2. Thực thi mẫu Cloud Phone","id":"2-thực-thi-mẫu-cloud-phone","depth":2},{"value":"Yêu cầu (cURL)","id":"yêu-cầu-curl-1","depth":3},{"value":"3. Phân tích tham số","id":"3-phân-tích-tham-số","depth":2},{"value":"Cách lấy ID?","id":"cách-lấy-id","depth":3},{"value":"Hiểu về templateParameter","id":"hiểu-về-templateparameter","depth":3},{"value":"4. Xử lý lỗi","id":"4-xử-lý-lỗi","depth":2},{"value":"Hướng dẫn nhanh Python","id":"hướng-dẫn-nhanh-python","depth":2}],"frontmatter":{"seo":{"title":"Mẫu gọi API qua HTTP"}},"lastModified":"2026-06-10T11:47:34.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/vi/rparobotic-process-automation/04-integration/call-template-via-http","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}