curl --request PATCH \
--url https://operator.opus.com/api/v1/code/{CODE_ID} \
--header 'Content-Type: application/json' \
--header 'x-service-key: {YOUR_SERVICE_KEY}' \
--data '{
"code": {
"description": "Collapses runs of whitespace and lowercases the result",
"sourceCode": "import re\n\n\ndef main(inputs):\n raw_text = inputs.get(\"raw_text\") or \"\"\n\n return {\"clean_text\": re.sub(r\"\\s+\", \" \", raw_text).strip().lower()}\n",
"categories": ["text_processing", "validation_and_normalization"],
"status": "active",
"isNew": false
}
}'
import requests
code_id = "{CODE_ID}"
url = f"https://operator.opus.com/api/v1/code/{code_id}"
headers = {
"Content-Type": "application/json",
"x-service-key": "{YOUR_SERVICE_KEY}"
}
source = '''import re
def main(inputs):
raw_text = inputs.get("raw_text") or ""
return {"clean_text": re.sub(r"\\s+", " ", raw_text).strip().lower()}
'''
payload = {
"code": {
"description": "Collapses runs of whitespace and lowercases the result",
"sourceCode": source,
"categories": ["text_processing", "validation_and_normalization"],
"status": "active",
"isNew": False,
}
}
response = requests.patch(url, json=payload, headers=headers)
print(response.json())
const codeId = "{CODE_ID}";
const source = `import re
def main(inputs):
raw_text = inputs.get("raw_text") or ""
return {"clean_text": re.sub(r"\\s+", " ", raw_text).strip().lower()}
`;
const response = await fetch(`https://operator.opus.com/api/v1/code/${codeId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"x-service-key": "{YOUR_SERVICE_KEY}",
},
body: JSON.stringify({
code: {
description: "Collapses runs of whitespace and lowercases the result",
sourceCode: source,
categories: ["text_processing", "validation_and_normalization"],
status: "active",
isNew: false,
},
}),
});
const data = await response.json();
console.log(data);
{
"id": "{CODE_ID}",
"name": "Normalize Text",
"description": "Collapses runs of whitespace and lowercases the result",
"versionId": "{NEW_CODE_VERSION_ID}"
}
Code
Update a Code Node
Revise a code node your organization owns, cutting a new version
PATCH
/
api
/
v1
/
code
/
{codeId}
curl --request PATCH \
--url https://operator.opus.com/api/v1/code/{CODE_ID} \
--header 'Content-Type: application/json' \
--header 'x-service-key: {YOUR_SERVICE_KEY}' \
--data '{
"code": {
"description": "Collapses runs of whitespace and lowercases the result",
"sourceCode": "import re\n\n\ndef main(inputs):\n raw_text = inputs.get(\"raw_text\") or \"\"\n\n return {\"clean_text\": re.sub(r\"\\s+\", \" \", raw_text).strip().lower()}\n",
"categories": ["text_processing", "validation_and_normalization"],
"status": "active",
"isNew": false
}
}'
import requests
code_id = "{CODE_ID}"
url = f"https://operator.opus.com/api/v1/code/{code_id}"
headers = {
"Content-Type": "application/json",
"x-service-key": "{YOUR_SERVICE_KEY}"
}
source = '''import re
def main(inputs):
raw_text = inputs.get("raw_text") or ""
return {"clean_text": re.sub(r"\\s+", " ", raw_text).strip().lower()}
'''
payload = {
"code": {
"description": "Collapses runs of whitespace and lowercases the result",
"sourceCode": source,
"categories": ["text_processing", "validation_and_normalization"],
"status": "active",
"isNew": False,
}
}
response = requests.patch(url, json=payload, headers=headers)
print(response.json())
const codeId = "{CODE_ID}";
const source = `import re
def main(inputs):
raw_text = inputs.get("raw_text") or ""
return {"clean_text": re.sub(r"\\s+", " ", raw_text).strip().lower()}
`;
const response = await fetch(`https://operator.opus.com/api/v1/code/${codeId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"x-service-key": "{YOUR_SERVICE_KEY}",
},
body: JSON.stringify({
code: {
description: "Collapses runs of whitespace and lowercases the result",
sourceCode: source,
categories: ["text_processing", "validation_and_normalization"],
status: "active",
isNew: false,
},
}),
});
const data = await response.json();
console.log(data);
{
"id": "{CODE_ID}",
"name": "Normalize Text",
"description": "Collapses runs of whitespace and lowercases the result",
"versionId": "{NEW_CODE_VERSION_ID}"
}
Revise a code node your organization owns.
Every field is optional — omitted fields keep their current value. Each call cuts a new code version rather than editing in place, so the previous state stays addressable.
Use the
id returned by Create a Code Node as {codeId}.
Requires the Code: Full permission at organization level, and a verified organization.
sourceCode, inputs and outputs are replaced wholesale, not merged field by field. Send the complete value you want stored — a partial inputs map drops every variable you left out.Omitting
sourceCode carries the current version’s source forward unchanged, so you can revise metadata without resending the module.Headers
string
required
Your API authentication key
Path Parameters
string
required
The code node to revise. This is
id from Create a Code Node — not its versionId. Must be a UUID.Body Parameters
The code node is nested under acode key.
object
required
The fields to change. All of them are optional.
string
Code node display name. Maximum 255 characters.
string
What the code does, shown under its name. Maximum 2048 characters.
string
Code icon as a base64-encoded SVG (or PNG) — a plain string, with no
data: prefix. Maximum 65535 characters.string
Replacement Python source. Must define
main(inputs). Replaces the stored source wholesale. Maximum 262144 bytes when UTF-8 encoded. Omit to carry the current source forward.object
Replacement input schema, keyed by each variable’s
variableName. Same shape and limits as on create — see Variable object.object
Replacement output schema. Same shape and limits as
inputs.string[]
Replacement category list. Maximum 5 entries. See Categories.
string
Code status —
active, inactive, soon or deprecated.boolean
Show the “new” badge on the code tile.
boolean
Show the “popular” badge on the code tile.
boolean
Show the “beta” badge on the code tile.
Response
string
required
The code id, unchanged.
string
required
Code node display name.
string
Code node description.
string
Id of the new version this call created. Differs on every successful call, including one that changes only a badge.
The response echoes only these four fields.
icon, categories, status and the badge flags are stored but not returned.Errors
Bad Request
Invalid body, a
codeId that is not a UUID, an inputs/outputs entry that is not a valid variable, or source that failed the security scan. A scan failure carries a violations array.Unauthorized
Missing, invalid, or expired API key.
Forbidden
The code node belongs to another organization, your organization is not verified to author code, the API key is not org-scoped, or the key owner lacks the Code: Full permission in the organization.
Not Found
No code node with that id.
curl --request PATCH \
--url https://operator.opus.com/api/v1/code/{CODE_ID} \
--header 'Content-Type: application/json' \
--header 'x-service-key: {YOUR_SERVICE_KEY}' \
--data '{
"code": {
"description": "Collapses runs of whitespace and lowercases the result",
"sourceCode": "import re\n\n\ndef main(inputs):\n raw_text = inputs.get(\"raw_text\") or \"\"\n\n return {\"clean_text\": re.sub(r\"\\s+\", \" \", raw_text).strip().lower()}\n",
"categories": ["text_processing", "validation_and_normalization"],
"status": "active",
"isNew": false
}
}'
import requests
code_id = "{CODE_ID}"
url = f"https://operator.opus.com/api/v1/code/{code_id}"
headers = {
"Content-Type": "application/json",
"x-service-key": "{YOUR_SERVICE_KEY}"
}
source = '''import re
def main(inputs):
raw_text = inputs.get("raw_text") or ""
return {"clean_text": re.sub(r"\\s+", " ", raw_text).strip().lower()}
'''
payload = {
"code": {
"description": "Collapses runs of whitespace and lowercases the result",
"sourceCode": source,
"categories": ["text_processing", "validation_and_normalization"],
"status": "active",
"isNew": False,
}
}
response = requests.patch(url, json=payload, headers=headers)
print(response.json())
const codeId = "{CODE_ID}";
const source = `import re
def main(inputs):
raw_text = inputs.get("raw_text") or ""
return {"clean_text": re.sub(r"\\s+", " ", raw_text).strip().lower()}
`;
const response = await fetch(`https://operator.opus.com/api/v1/code/${codeId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"x-service-key": "{YOUR_SERVICE_KEY}",
},
body: JSON.stringify({
code: {
description: "Collapses runs of whitespace and lowercases the result",
sourceCode: source,
categories: ["text_processing", "validation_and_normalization"],
status: "active",
isNew: false,
},
}),
});
const data = await response.json();
console.log(data);
{
"id": "{CODE_ID}",
"name": "Normalize Text",
"description": "Collapses runs of whitespace and lowercases the result",
"versionId": "{NEW_CODE_VERSION_ID}"
}
Was this page helpful?