{"title":"Scripts API","slug":"scripts","category":"api","summary":"Lưu trữ script cố định — lưu shell, Python, hoặc Node script tái sử dụng và lấy qua curl | bash.","audience":["human","llm"],"tags":["api","scripts","automation","snippets"],"difficulty":"beginner","updated":"2026-06-27","word_count":178,"read_minutes":1,"llm_context":"Auth: Mind Key or JWT\nStore: POST /script { name, content, description?, language? }\nFetch as text: GET /script/:name (returns text/plain, curl | bash ready)\nInfo: GET /script/:name/info (metadata without content)\nList: GET /scripts (JSON array)\nDelete: DELETE /script/:name\nUse case: store deployment scripts, config generators, troubleshooting snippets\n","lang":"vi","translated":true,"requested_lang":"vi","content_markdown":"\n# Scripts API\n\nScripts API cung cấp lưu trữ cố định cho script tái sử dụng. Script được đặt tên\nvà đánh phiên bản trong một mind, có thể lấy dưới dạng văn bản thuần — hoàn hảo\ncho mẫu `curl | bash`.\n\n## Các endpoint\n\n### POST /script\n\nLưu hoặc cập nhật một script.\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/script \\\n  -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"name\": \"deploy-synapse\",\n    \"content\": \"#!/bin/bash\\nset -euo pipefail\\ngit pull\\nnpm ci\\nnpm run build\\ndocker compose up -d\",\n    \"description\": \"Deploy Synapse to production\",\n    \"language\": \"bash\"\n  }'\n```\n\n### GET /script/:name\n\nLấy nội dung script dưới dạng `text/plain`. Hoàn hảo để pipe vào bash.\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/script/deploy-synapse | bash\n```\n\n### GET /script/:name/info\n\nLấy metadata script mà không có nội dung.\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/script/deploy-synapse/info\n```\n\nPhản hồi:\n\n```json\n{\n  \"name\": \"deploy-synapse\",\n  \"description\": \"Deploy Synapse to production\",\n  \"language\": \"bash\",\n  \"size_bytes\": 142,\n  \"created_at\": \"2026-06-27T...\",\n  \"updated_at\": \"2026-06-27T...\"\n}\n```\n\n### GET /scripts\n\nLiệt kê tất cả script trong mind hiện tại.\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/scripts\n```\n\n### DELETE /script/:name\n\nXóa một script.\n\n```bash\ncurl -X DELETE -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/script/deploy-synapse\n```\n\n## Trường hợp sử dụng phổ biến\n\n### Script triển khai\n\nLưu quy trình triển khai chuẩn để LLM có thể chạy mà không cần suy luận lại các\nbước mỗi lần:\n\n```bash\n# LLM stores this once\ncurl -X POST .../script -d '{\n  \"name\": \"deploy-vps1\",\n  \"content\": \"#!/bin/bash\\nssh vps1 \\\"cd /opt/synapse && git pull && docker compose up -d --build\\\"\",\n  \"language\": \"bash\"\n}'\n\n# Later sessions just run it\ncurl -H \"Authorization: ...\" .../script/deploy-vps1 | bash\n```\n\n### Đoạn mã khắc phục sự cố\n\nLưu các lệnh chẩn đoán cho các vấn đề phổ biến:\n\n```bash\ncurl -X POST .../script -d '{\n  \"name\": \"check-docker\",\n  \"content\": \"#!/bin/bash\\ndocker ps\\ndocker stats --no-stream\\ndocker system df\",\n  \"description\": \"Quick Docker health check\",\n  \"language\": \"bash\"\n}'\n```\n\n### Trình tạo cấu hình\n\nLưu các script tạo cấu hình:\n\n```bash\ncurl -X POST .../script -d '{\n  \"name\": \"gen-nginx-conf\",\n  \"content\": \"#!/usr/bin/env python3\\nimport sys\\n# ... generate nginx config from template ...\",\n  \"language\": \"python\"\n}'\n```\n\n## Bước tiếp theo\n\n- [Variables API](/docs/api/variables)\n- [Cron & Scheduler](/docs/api/cron)\n","content_html":"<h1>Scripts API</h1>\n<p>Scripts API cung cấp lưu trữ cố định cho script tái sử dụng. Script được đặt tên\nvà đánh phiên bản trong một mind, có thể lấy dưới dạng văn bản thuần — hoàn hảo\ncho mẫu <code>curl | bash</code>.</p>\n<h2>Các endpoint</h2>\n<h3>POST /script</h3>\n<p>Lưu hoặc cập nhật một script.</p>\n<pre><code class=\"hljs language-bash\">curl -X POST https://synapse.schaefer.zone/script \\\n  -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n  -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{\n    &quot;name&quot;: &quot;deploy-synapse&quot;,\n    &quot;content&quot;: &quot;#!/bin/bash\\nset -euo pipefail\\ngit pull\\nnpm ci\\nnpm run build\\ndocker compose up -d&quot;,\n    &quot;description&quot;: &quot;Deploy Synapse to production&quot;,\n    &quot;language&quot;: &quot;bash&quot;\n  }&#x27;</span></code></pre><h3>GET /script/:name</h3>\n<p>Lấy nội dung script dưới dạng <code>text/plain</code>. Hoàn hảo để pipe vào bash.</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/script/deploy-synapse | bash</code></pre><h3>GET /script/:name/info</h3>\n<p>Lấy metadata script mà không có nội dung.</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/script/deploy-synapse/info</code></pre><p>Phản hồi:</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;name&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;deploy-synapse&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;description&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Deploy Synapse to production&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;language&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;bash&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;size_bytes&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-number\">142</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;created_at&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-27T...&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;updated_at&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-27T...&quot;</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><h3>GET /scripts</h3>\n<p>Liệt kê tất cả script trong mind hiện tại.</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/scripts</code></pre><h3>DELETE /script/:name</h3>\n<p>Xóa một script.</p>\n<pre><code class=\"hljs language-bash\">curl -X DELETE -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/script/deploy-synapse</code></pre><h2>Trường hợp sử dụng phổ biến</h2>\n<h3>Script triển khai</h3>\n<p>Lưu quy trình triển khai chuẩn để LLM có thể chạy mà không cần suy luận lại các\nbước mỗi lần:</p>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># LLM stores this once</span>\ncurl -X POST .../script -d <span class=\"hljs-string\">&#x27;{\n  &quot;name&quot;: &quot;deploy-vps1&quot;,\n  &quot;content&quot;: &quot;#!/bin/bash\\nssh vps1 \\&quot;cd /opt/synapse &amp;&amp; git pull &amp;&amp; docker compose up -d --build\\&quot;&quot;,\n  &quot;language&quot;: &quot;bash&quot;\n}&#x27;</span>\n\n<span class=\"hljs-comment\"># Later sessions just run it</span>\ncurl -H <span class=\"hljs-string\">&quot;Authorization: ...&quot;</span> .../script/deploy-vps1 | bash</code></pre><h3>Đoạn mã khắc phục sự cố</h3>\n<p>Lưu các lệnh chẩn đoán cho các vấn đề phổ biến:</p>\n<pre><code class=\"hljs language-bash\">curl -X POST .../script -d <span class=\"hljs-string\">&#x27;{\n  &quot;name&quot;: &quot;check-docker&quot;,\n  &quot;content&quot;: &quot;#!/bin/bash\\ndocker ps\\ndocker stats --no-stream\\ndocker system df&quot;,\n  &quot;description&quot;: &quot;Quick Docker health check&quot;,\n  &quot;language&quot;: &quot;bash&quot;\n}&#x27;</span></code></pre><h3>Trình tạo cấu hình</h3>\n<p>Lưu các script tạo cấu hình:</p>\n<pre><code class=\"hljs language-bash\">curl -X POST .../script -d <span class=\"hljs-string\">&#x27;{\n  &quot;name&quot;: &quot;gen-nginx-conf&quot;,\n  &quot;content&quot;: &quot;#!/usr/bin/env python3\\nimport sys\\n# ... generate nginx config from template ...&quot;,\n  &quot;language&quot;: &quot;python&quot;\n}&#x27;</span></code></pre><h2>Bước tiếp theo</h2>\n<ul>\n<li><a href=\"/docs/api/variables\">Variables API</a></li>\n<li><a href=\"/docs/api/cron\">Cron &amp; Scheduler</a></li>\n</ul>\n","urls":{"html":"/docs/api/scripts","text":"/docs/api/scripts?format=text","json":"/docs/api/scripts?format=json","llm":"/docs/api/scripts?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}