{"_id":"56c50629bdcde80d00498657","editedParams2":true,"version":{"_id":"56c50626bdcde80d00498635","project":"54774d9af3736008009e9e0e","__v":10,"createdAt":"2016-02-17T23:45:42.869Z","releaseDate":"2016-02-17T23:45:42.869Z","categories":["56c50628bdcde80d00498636","56c50628bdcde80d00498637","56c50628bdcde80d00498638","56c50628bdcde80d00498639","56c50628bdcde80d0049863a","56c50628bdcde80d0049863b","56c50628bdcde80d0049863c","56c50628bdcde80d0049863d","56c50628bdcde80d0049863e","56c50628bdcde80d0049863f","56c50628bdcde80d00498640","56c50628bdcde80d00498641","56c50628bdcde80d00498642","56c50628bdcde80d00498643","56c50628bdcde80d00498644","56c50628bdcde80d00498645","56c50628bdcde80d00498646","56c50628bdcde80d00498647","56c506a018f0c90d002808de","56c6b0baf795cf0d003ec13e","56fe58eb5a08190e00085149","571764513cf2960e0009a635","571fc008ffbc6a2000b25bb5","5739ca371f4b740e00b06e09","577522f197a3830e004bcc1b","57753d5ffecd260e00d86ce6","57adb71efaa7a10e004495b6"],"is_deprecated":true,"is_hidden":false,"is_beta":false,"is_stable":false,"codename":"API v1.1","version_clean":"0.1.1","version":"0.1.1"},"githubsync":"","category":{"_id":"56c50628bdcde80d0049863a","pages":["56c50629bdcde80d00498654","56c50629bdcde80d00498655","56c50629bdcde80d00498656","56c50629bdcde80d00498657","56c50629bdcde80d00498658","56c50629bdcde80d00498659","56c50629bdcde80d0049865a","56c50629bdcde80d0049865b","56c50629bdcde80d0049865c","56c50629bdcde80d0049865d"],"project":"54774d9af3736008009e9e0e","version":"56c50626bdcde80d00498635","__v":1,"sync":{"url":"","isSync":false},"reference":true,"createdAt":"2015-03-17T14:13:34.744Z","from_sync":false,"order":5,"slug":"codebox","title":"Snippets - Scripts"},"user":"54774c47f3736008009e9e0c","project":"54774d9af3736008009e9e0e","parentDoc":null,"__v":0,"editedParams":true,"metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-02-20T16:54:10.423Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[{"name":"","code":"{\n  \"description\": \"Kills chosen monster\",\n  \"links\": {\n    \"run\": \"/v1.1/instances/rivia/snippets/scripts/12/run/\",\n    \"self\": \"/v1.1/instances/rivia/snippets/scripts/12/\",\n    \"traces\": \"/v1.1/instances/rivia/snippets/scripts/12/traces/\",\n    \"runtimes\": \"/v1.1/instances/rivia/snippets/scripts/runtimes/\"\n  },\n  \"created_at\": \"2016-03-10T20:34:39.254393Z\",\n  \"updated_at\": \"2016-03-10T20:34:39.254417Z\",\n  \"label\": \"Kill a Monster\",\n  \"source\": \"if \\\"monster\\\" in ARGS:\\n print \\\"Killed \\\" + ARGS[\\\"monster\\\"]\\nelse:\\n print \\\"Nothing to kill\\\"\",\n  \"runtime_name\": \"python\",\n  \"config\": {},\n  \"id\": 12\n}","language":"json","status":201},{"code":"{\n  \"runtime_name\": [\n    \"This field is required.\"\n  ],\n  \"name\": [\n    \"This field is required.\"\n  ]\n}","status":400,"language":"json"},{"language":"json","code":"{\n  \"detail\": \"No such API Key.\"\n}","status":403},{"status":404,"language":"json","code":"{\n  \"detail\": \"Instance was not found.\"\n}"}]},"settings":"56c50c06d1b8770d00922288","examples":{"codes":[{"language":"curl","code":"curl -X POST \\\n-H \"X-API-KEY: <ACCOUNT_KEY>\" \\\n-H \"Content-Type: application/json\" \\\n-d '{\"label\":\"Kill a Monster\",\n     \"source\":\"if \\\"monster\\\" in ARGS:\\n print \\\"Killed \\\" + ARGS[\\\"monster\\\"]\\nelse:\\n print \\\"Nothing to kill\\\"\",\n     \"runtime_name\":\"python\",\n     \"description\":\"Kills chosen monster\"}' \\\n\"https://api.syncano.io/v1.1/instances/<instance_name>/snippets/scripts/\"","name":""},{"language":"python","code":"import syncano\nfrom syncano.models import Script\n\nconnection = syncano.connect(api_key=\"ACCOUNT_KEY\", instance_name=\"INSTANCE_NAME\")\n\nScript.please.create(\n    label=\"kill a monster\",\n    source=\"if \\\"monster\\\" in ARGS:\\n print \\\"Killed \\\" + ARGS[\\\"monster\\\"]\\nelse:\\n print \\\"Nothing to kill\\\"\",\n    runtime_name=\"python\",\n    description=\"this codebox kills a monster\"\n)\n"},{"language":"javascript","code":"var Syncano = require(\"syncano\");\nvar connection = Syncano({accountKey: \"ACCOUNT_KEY\"});\nvar Script = connection.Script;\n\nvar options = { \n  \"label\":\"Kill a Monster\",\n  \"source\":\"ARGS.monster ? console.log(\\\"Killed\\\" + ARGS.monster) : console.log(\\\"Nothing to kill\\\")\",\n  \"runtime_name\":\"nodejs\",\n  \"description\":\"Kills chosen monster\",\n  \"instanceName\": \"INSTANCE_NAME\"\n};\n\nScript.please().create(options).then(callback);"}]},"method":"post","auth":"required","params":[{"_id":"54d8b350628f540d00f3e4ae","ref":"","in":"path","required":true,"desc":"Instance name","default":"","type":"string","name":"instance_name"},{"_id":"54e766b27e677b23005325ab","ref":"","in":"body","required":true,"desc":"CodeBox label","default":"","type":"string","name":"label"},{"_id":"54e766b27e677b23005325a9","ref":"","in":"body","required":true,"desc":"Source code to execute when running Script","default":"","type":"string","name":"source"},{"_id":"54e766b27e677b23005325ac","ref":"","in":"body","required":true,"desc":"Runtime name. Make a call to `/snippets/scripts/runtimes/` to get a current list of supported runtimes.","default":"","type":"string","name":"runtime_name"},{"_id":"54e766b27e677b23005325ad","ref":"","in":"body","required":false,"desc":"Configuration dictionary, that every Script run will have access to. Use .e.g for storing API Keys, or any other values you don't want to provide in code.","default":"{}","type":"string","name":"config"},{"_id":"54e766b27e677b23005325aa","ref":"","in":"body","required":false,"desc":"Script description","default":"","type":"string","name":"description"}],"url":"/instances/:instance_name/snippets/scripts/"},"isReference":true,"order":3,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Returns\"\n}\n[/block]\nInformation about newly created Script.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Passing source code\",\n  \"body\": \"When using our API directly to create a Script, it's important to properly escape all characters like newline, or quotation marks. Otherwise Syncano might not be able to properly read the code you're sending, and you might see 400 error as a response.\\n\\nIt's also definitely much easier to write, save and execute a Script when using our [Dashboard](https://dashboard.syncano.io) than to do it by direct API calls. We highly recommend using the Dashboard.\"\n}\n[/block]","excerpt":"Creates a Script with a given source code, name and runtime environment. Pass additional configuration in `config`, if you want to have access to any kind of code independent information (like API Keys, passwords etc.). You can also add description, if the name is not sufficient.\nRequires an `Account Key`.","slug":"script-add","type":"endpoint","title":"Script - add"}

postScript - add

Creates a Script with a given source code, name and runtime environment. Pass additional configuration in `config`, if you want to have access to any kind of code independent information (like API Keys, passwords etc.). You can also add description, if the name is not sufficient. Requires an `Account Key`.

Definition

{{ api_url }}{{ page_api_url }}

Parameters

Path Params

instance_name:
required
string
Instance name

Body Params

label:
required
string
CodeBox label
source:
required
string
Source code to execute when running Script
runtime_name:
required
string
Runtime name. Make a call to `/snippets/scripts/runtimes/` to get a current list of supported runtimes.
config:
string{}
Configuration dictionary, that every Script run will have access to. Use .e.g for storing API Keys, or any other values you don't want to provide in code.
description:
string
Script description

Examples


Result Format


Documentation

[block:api-header] { "type": "basic", "title": "Returns" } [/block] Information about newly created Script. [block:callout] { "type": "warning", "title": "Passing source code", "body": "When using our API directly to create a Script, it's important to properly escape all characters like newline, or quotation marks. Otherwise Syncano might not be able to properly read the code you're sending, and you might see 400 error as a response.\n\nIt's also definitely much easier to write, save and execute a Script when using our [Dashboard](https://dashboard.syncano.io) than to do it by direct API calls. We highly recommend using the Dashboard." } [/block]

User Information

Try It Out

post
{{ tryResults.results }}
Method{{ tryResults.method }}
Request Headers
{{ tryResults.requestHeaders }}
URL{{ tryResults.url }}
Request Data
{{ tryResults.data }}
Status
Response Headers
{{ tryResults.responseHeaders }}