Change the Template
Every application component, library, container and agent refers to the template it was created from. You can switch an existing resource to a different template or template version, for example to move it to the latest platform version. Many resources can be changed in one batch. There is no separate upgrade operation: moving to a newer version is a change to the same template with that version.
What a change does, which templates and versions are allowed and the preconditions are described once in the Self-Service Portal Guide: Change Template and Version. In short:
- The resource switches to the new template at once, when the change succeeds.
- The file changes go to a new branch, created from the default branch with one commit:
.codenow.yaml, merged with the new template and edited in place, so comments and formatting are kept (pipelines and CI settings still at the old template's defaults move to the new defaults, values you changed are kept, settings the current template doesn't declare are added with the new template's default; environment variables, triggers and advanced mode are untouched), plus the files you list inincludePaths. Nothing is written to the default branch. You review the branch and merge it yourself; CodeNOW opens no merge request. - Until the branch is merged, builds of the default branch already use the new template, together with the
.codenow.yamland the other files still on the default branch. - Outside advanced mode, the next build renders the Dockerfile and Helm chart from the new template. In advanced mode, and for a container's Dockerfile, you include the template's files in the branch or apply the changes yourself. Existing builds, packages and connections are not touched.
- Any published version of any template can be chosen, platform (
custom: false) and custom (custom: true) alike. - The resource must be ready, no build of it may be running, and you need update permission on it.
- Submitting the template and version the resource already has is not an error and does not change the template. A branch is created only when
.codenow.yamlor an included file differs from the default branch; otherwise nothing changes.
The Template Block
The detail and list responses of all four resource kinds carry a template field (schema ResourceTemplate). A container without a template reference omits it.
"template": {
"id": "java-maven-micronaut",
"name": "Java Maven Micronaut",
"custom": false,
"version": "3.3.0",
"latestVersion": "3.4.0",
"outdated": true
}
| Field | Meaning |
|---|---|
id | Template id. Send it back as id in a change request. |
name | Human-readable name; null when the referenced version no longer exists. |
custom | true for a custom template (published in your account), false for a platform template (provided by CodeNOW). Send it back as custom in a change request. |
version | The version the resource is on. |
latestVersion | The newest available version, for custom templates too; null when no version is available any more. |
outdated | true only for a platform template older than latestVersion; never true for custom templates. |
For custom templates, outdated stays false but latestVersion is filled in, so compare version with latestVersion yourself to find resources that are not on the newest custom version.
The Change Response
The change operations return TemplateChangeResult: the resource's template block as it is after the change, and the branch that holds the file changes.
{
"template": {
"id": "java-maven-micronaut",
"name": "Java Maven Micronaut",
"custom": false,
"version": "3.4.0",
"latestVersion": "3.4.0",
"outdated": false
},
"branch": {
"name": "codenow/change-template-orders-java-maven-micronaut-3.4.0",
"baseBranch": "main",
"baseCommit": "3f2c1a9",
"commit": "8d04b7e",
"paths": [".codenow.yaml", "Dockerfile"],
"webUrl": null
}
}
| Field | Meaning |
|---|---|
template | The resource's template after the change. The resource already uses it. |
branch | The new branch, or null when there was nothing to commit (every included file already matched the repository); then no branch was created. |
branch.name | The name of the new branch. The preview's outcome.branch shows it before you confirm. See Branch Names. |
branch.baseBranch, branch.baseCommit | The default branch and the commit the new branch starts from. Merge the new branch into baseBranch. |
branch.commit | The single commit on the new branch. |
branch.paths | The paths the commit changes, relative to the resource root. |
branch.webUrl | Reserved for a link to the branch; currently always null. |
The change operations do not return the updated resource. If you need it, call the resource's detail operation again.
Branch Names
Don't build the branch name yourself: read it from the preview's outcome.branch before you confirm, and from branch.name in the change response. Both always agree. As an illustration only, not a contract, names currently look like codenow/change-template-<resource>-<templateId>-<version>, for example codenow/change-template-orders-java-gradle-2.0.0:
<resource>is the resource's id and is always part of the name, so two resources in one repository never get the same branch;- in each part, any character other than letters, digits,
.,_and-becomes-; - a name is at most 100 characters long. A longer name is cut to 91 characters and ends with
-and 8 hexadecimal characters of a hash; it is still the same for the same change.
Operations
| Operation | Endpoint |
|---|---|
| Change the template of an application component | PUT /applications/{applicationId}/components/{applicationComponentId}/template |
| Change the template of a library | PUT /libraries/{libraryId}/template |
| Change the template version of a container | PUT /containers/{containerId}/template |
| Change the template of an agent | PUT /agent-swarms/{agentSwarmId}/agents/{agentId}/template |
| Preview a template change of an application component | POST /applications/{applicationId}/components/{applicationComponentId}/template/preview |
| Preview a template change of a library | POST /libraries/{libraryId}/template/preview |
| Preview a template change of a container | POST /containers/{containerId}/template/preview |
| Preview a template change of an agent | POST /agent-swarms/{agentSwarmId}/agents/{agentId}/template/preview |
| Read a scaffold file of a template change preview of an application component | POST /applications/{applicationId}/components/{applicationComponentId}/template/preview/file |
| Read a scaffold file of a template change preview of a library | POST /libraries/{libraryId}/template/preview/file |
| Read a scaffold file of a template change preview of a container | POST /containers/{containerId}/template/preview/file |
| Read a scaffold file of a template change preview of an agent | POST /agent-swarms/{agentSwarmId}/agents/{agentId}/template/preview/file |
| List versions of a template | GET /templates/{templateId}/versions?custom= |
| Get a template version | GET /templates/{templateId}?custom=&version= |
All operations use the media type application/vnd.codenow.v1+json.
Request Body
The change and preview operations take the same body (schema TemplateChangeRequest). The preview file operations take the same fields except includePaths, plus path (schema TemplatePreviewFileRequest). The fields are named as in resource creation:
{
"id": "java-maven-micronaut",
"version": "3.4.0",
"custom": false,
"properties": {
"javaVersion": "21"
},
"includePaths": ["Dockerfile", "src/main/resources/logback.xml"]
}
| Field | Required | Meaning |
|---|---|---|
id | yes | Target template. It must be offered when creating a resource of the same kind: /templates/application_components, /templates/libraries or /templates/agents. For containers it is always container. |
version | yes | Target version: any version from /templates/{templateId}/versions, for platform and custom templates alike. |
custom | yes | true for a template published in your account, false for one provided by CodeNOW. Platform and custom templates share one id namespace, so the flag is mandatory. |
properties | no | Template properties ("key": "value") of the target version, as on creation. Omitted keys keep the resource's current values. Only the properties you send are type-validated. |
includePaths | no | Change and preview only: the files to commit to the new branch besides .codenow.yaml, which is always included. Paths are relative to the resource root and must come from the preview: a files[].path with selectable: true, or an otherFiles[].path that can be replaced in the repository: not a symbolic link and not below one, no repository file at a parent path and no repository directory at the path itself. otherFiles[].symlink shows the link case; a parent-file or directory conflict is not visible in advance. Anything else is rejected with 400 E7018. Naming .codenow.yaml is ignored, never an error. Omitted, null or []: only .codenow.yaml. An included file is replaced by the whole file rendered from the new template; lines of your own in it are edited on the branch before you merge. The preview file operations ignore this field. |
Send the same body, including includePaths, to the preview and then to the change, so the change does exactly what the preview showed.
Preview a Change
Each change operation has a read-only preview: POST …/template/preview on the same resource path, with the same request body. It returns what the change would do (schema TemplatePreview): what CodeNOW does, what is left to you, and the branch confirming would create. Nothing is written, no branch is created and no build is started.
The recommended client flow is preview → choose the files → preview again → change → merge the branch:
- Call the preview with the target
id,version,customand anyproperties. - Show or check the
effects(PLATFORMeffects happen automatically,USEReffects are left to you) and the diffs infiles. Read scaffold files on demand with preview/file. - Choose which files go into the branch: any
files[]entry withselectable: trueand anyotherFiles[]entry. Call the preview again with them inincludePathsto see the resultingoutcomeand effects. - If
outcome.branchExistsisfalse, call the change with the same body. - Review the new branch in the repository and merge it into the default branch.
The preview validates the request like the change (E7011, E7001, E7018, E7020, 400, 403, 404), so rejections show up before you confirm. If the repository's default branch cannot be read, it returns 502 E7014 instead of a partial preview. It is not blocked by a running build or by an existing branch: it never returns 409. An existing branch shows as outcome.branchExists: true. Previewing the template and version the resource already has returns IDENTICAL for every vsCurrentTemplate comparison; vsRepository still shows where the repository differs from the template. If the preview is larger than the API passes on, it returns 502 without an errorId; if CodeNOW doesn't answer in time, 504. In both cases nothing was changed; retry later.
The Preview Response
{
"repository": { "branch": "main", "commit": "3f2c1a9", "advancedMode": true },
"files": [
{
"path": ".codenow.yaml",
"managedBy": "PLATFORM",
"selectable": false,
"vsRepository": { "result": "CHANGED", "current": "<base64>", "target": "<base64>" }
},
{
"path": "Dockerfile",
"managedBy": "REPOSITORY",
"selectable": true,
"vsRepository": { "result": "CHANGED", "current": "<base64>", "target": "<base64>" }
}
],
"otherFiles": [ { "path": "src/main/resources/logback.xml", "inRepository": true, "binary": false } ],
"outcome": {
"branch": "codenow/change-template-orders-java-maven-micronaut-3.4.0",
"branchExists": false,
"baseBranch": "main",
"baseCommit": "3f2c1a9",
"paths": [".codenow.yaml", "Dockerfile"]
},
"effects": [
{ "code": "CODENOW_YAML_MERGED", "actor": "PLATFORM", "message": "…" },
{ "code": "PIPELINE_CHANGED", "actor": "PLATFORM", "message": "…", "key": "build.pipelines.release.pipeline", "previousValue": "maven-release-3.3", "value": "maven-release-3.4" },
{ "code": "BRANCH_CREATED", "actor": "PLATFORM", "message": "…" },
{ "code": "MERGE_BRANCH", "actor": "USER", "message": "…" },
{ "code": "TEMPLATE_SWITCHED_BEFORE_MERGE", "actor": "USER", "message": "…" },
{ "code": "OTHER_TEMPLATE_FILES", "actor": "USER", "message": "…" }
]
}
This example is the preview with "includePaths": ["Dockerfile"] for a component in advanced mode.
-
repository— the repository's default branch and its headcommit, which the preview was computed against. There is no lock: the branch may move before you confirm.advancedModeistrueorfalseas set byadvancedMode.enabledin that branch's.codenow.yaml, andnullwhen the target template declares no advanced mode setting (for exampledocker-generic,helm-genericand other runnable templates, libraries and containers). Which files you have to handle is decided per file bymanagedBy, not by this flag. -
files— the files CodeNOW manages:.codenow.yaml, theDockerfileand thehelm/directory. For a change to another version of the same template, the list covers the whole rendered template (when the current version can still be rendered), so you can see everything that changed between the two versions; the files outside that set areREPOSITORYand carry onlyvsCurrentTemplate(old version compared with new version).managedBy—PLATFORMwhen CodeNOW takes care of the file:.codenow.yamlalways (merged and committed to the branch); the Dockerfile and Helm chart when advanced mode is off (rendered at the next build).REPOSITORYwhen the repository's copy is authoritative: the Dockerfile and Helm chart in advanced mode; for a runnable target template (for exampledocker-generic,helm-generic), for every kind, the Dockerfile andhelm/files it needs, whatever the advanced mode; a container's Dockerfile always; and every other template file. You include such a file in the branch or apply the change yourself. Decide per file onmanagedBy, never onadvancedModealone.selectable—truewhen the path can go intoincludePaths: the new template renders it, it ismanagedBy: REPOSITORYand not.codenow.yaml, and it can be replaced in the repository (not a symbolic link and not below one, no repository file at a parent path, no repository directory at the path itself).falsefor.codenow.yaml(always included), for files CodeNOW renders at build time, for symbolic links (symlink: true) and for a file only the previous version renders. Identical content does not make a file unselectable; an unchanged file is simply not part of the commit.symlink—truewhen the path is a symbolic link in the repository or lies below a linked directory. CodeNOW never reads it: no comparison with the repository is returned for it, it is not selectable, and naming it inincludePathsanswers 400E7018.vsCurrentTemplate— the file rendered from the current template compared with the new template.vsRepository— the file on the default branch compared with the new template. A pair is omitted when it doesn't apply.result—CHANGED,IDENTICAL,TARGET_ONLY(only the new template has the file) orOTHER_ONLY(only the current template or the repository has it).currentandtargetare the file contents, base64-encoded, ornullwhen the file doesn't exist on that side.- For
.codenow.yaml, thevsRepositorytarget is the merged file the change will commit to the branch. For any other file you include, the commit holds thetargetcontent as it is.
-
otherFiles— the application scaffold: every file the new template renders outside.codenow.yaml, theDockerfileand thehelm/directory, by name only.inRepositorytells whether a file of that name already exists,binarywhether its content is not text (for example a Gradle wrapper JAR), andsymlinkwhether the path is a symbolic link in the repository or lies below a linked directory; such a path is never read and can't be put intoincludePaths(400E7018). For a change to another version of the same template, these are the same files whose version comparison is infiles. CodeNOW does not need them; each one that can be replaced in the repository (seeincludePathsabove) can be put intoincludePaths, or you apply it by hand as far as your resource needs it. Fetch a file's content with preview/file. -
outcome— what confirming with this request'sincludePathswould create:branch— the name of the new branch (see Branch Names), ornullwhen nothing would be committed;branchExists—truewhen a branch of that name already exists. The change would then fail with 409E7019; merge or delete that branch first, then preview again.falsewhenbranchisnull: with nothing to commit, the check is skipped;baseBranch,baseCommit— the default branch and the commit the branch would start from;paths— the paths the commit would change. Included files that already match the repository are skipped.
When nothing would be committed,
branchisnullandpathsis empty: confirming only switches the template, creates no branch, and there is nothing to merge. -
effects— the consequences, each with acode, anactorand an end-usermessage. Key oncode, not on the message; new codes can be added. The pipeline and CI setting effects also carry up to four optional strings, omitted where they don't apply:key— the dotted.codenow.yamlkey, for exampleruntime.image, orbuild.pipelines.release.pipeline/build.pipelines.preview.pipelinefor pipelines;previousValue— the value in the default branch's.codenow.yamlbefore the change, only when it changes or the key is removed;value— the value after the change; forPIPELINE_KEPT,PIPELINE_DEFAULT_KEPT,CI_PROPERTY_KEPTandCI_PROPERTY_DEFAULT_KEPT, the unchanged value; omitted when the key is removed;defaultValue— the new template's default forkey, never the previous template's; omitted when it has none.
Every pipeline effect (
PIPELINE_…) and CI setting effect (CI_PROPERTY_…) carrieskey, the dotted.codenow.yamlpath, plus the fields named in its row of the table below. Effects outside these two families carry none of the four fields.
actor | code | Meaning |
|---|---|---|
PLATFORM | BRANCH_CREATED | The new branch will be created with one commit holding .codenow.yaml and the included files. |
PLATFORM | CODENOW_YAML_MERGED | .codenow.yaml will be merged and committed to the new branch. |
PLATFORM | CODENOW_YAML_ABSENT | The repository has no .codenow.yaml; it is not part of the commit. |
PLATFORM | PIPELINE_CHANGED | A pipeline still at the old template's default will be switched to the new template's default. key, previousValue → value. |
PLATFORM | PIPELINE_DEFAULT_KEPT | A pipeline equal to the previous template's default is kept, because the new template has none. key, value. |
PLATFORM | CI_PROPERTY_CHANGED | A CI setting still at the old template's default will follow the new template's default. key, previousValue → value, defaultValue. |
PLATFORM | CI_PROPERTY_ADDED | A CI setting the current template doesn't declare will be added with the new template's default. key, value, defaultValue. |
PLATFORM | CI_PROPERTY_DROPPED | A CI setting the new template no longer declares will be removed. key, previousValue. |
PLATFORM | CI_PROPERTY_DEFAULT_KEPT | A CI setting equal to the previous template's default is kept, because the new template has none. key, value. |
PLATFORM | CI_FILES_RENDERED_AT_NEXT_BUILD | The Dockerfile and Helm chart will be rendered from the new template at the next build (advanced mode off). |
PLATFORM | CURRENT_TEMPLATE_UNAVAILABLE | The current template version is no longer available, so vsCurrentTemplate is omitted. |
USER | MERGE_BRANCH | Review the new branch and merge it into the default branch. |
USER | BRANCH_EXISTS | The branch already exists. Merge or delete it before you confirm. |
USER | TEMPLATE_SWITCHED_BEFORE_MERGE | The resource is on the new template as soon as the change succeeds, while the default branch keeps the old files until you merge the branch. |
USER | APPLY_REPOSITORY_CHANGES | Changed Dockerfile or helm/ files that the repository manages (managedBy: REPOSITORY) are not included. Include them, or apply the changes yourself. Not raised when only other files differ. |
USER | CODENOW_YAML_NOT_MERGED | The repository's .codenow.yaml could not be parsed. CodeNOW leaves it as it is; adapt it to the new template by hand. |
USER | PIPELINE_KEPT | A pipeline you customised is kept; the message names the new template's default if you want to switch. key, value (yours), defaultValue (absent when the new template has none). |
USER | CI_PROPERTY_KEPT | A CI setting you customised is kept; reported only when its default changed between the templates or the current template is unknown. key, value (yours), defaultValue (absent when the new template has none or it is blank). |
USER | OTHER_TEMPLATE_FILES | The new template provides further files, listed in otherFiles; they are committed only when included. |
Scaffold File Content
The preview lists the application scaffold (otherFiles) by name only. A further read-only operation on the same resource path, POST …/template/preview/file, returns the content of one file. It takes the preview's request body plus path (it ignores includePaths), validates it like the preview and is not blocked by a running build. Like the preview, it needs update permission on the resource (403 otherwise), and it serves only the files the preview lists in otherFiles: the new template's files rendered for the resource and, for a file that already exists, the default branch's copy. .codenow.yaml, the Dockerfile and helm/ files are not served by it (their contents are already in the preview's files). There is no public operation that downloads all scaffold files at once.
The body (schema TemplatePreviewFileRequest) has the fields of TemplateChangeRequest plus path, one of the preview's otherFiles[].path. Any other path, including .codenow.yaml, the Dockerfile and helm/ files, is rejected with 400 E7017. The response (schema TemplatePreviewFileContent) has the same pair shape as files:
{
"path": "src/main/resources/logback.xml",
"inRepository": true,
"binary": false,
"vsRepository": { "result": "CHANGED", "current": "<base64>", "target": "<base64>" }
}
vsRepository.targetis the file rendered from the new template with the resource's properties;currentis the default branch's copy wheninRepositoryistrue, otherwisenullandresultisTARGET_ONLY.- For a binary file (
binary: true: it contains a NUL byte or is not valid UTF-8),vsRepositoryis omitted: the content of a binary file is not returned. To get the file into the repository, include its path inincludePathsso it is committed to the branch (not possible for a symbolic link).
curl -X POST "$API/libraries/$LIBRARY_ID/template/preview/file" \
-H "X-Codenow-Api-Key: $KEY" \
-H "Content-Type: application/vnd.codenow.v1+json" \
-H "Accept: application/vnd.codenow.v1+json" \
-d '{"id": "my-java-service", "custom": true, "version": "2.0.0", "path": "src/main/resources/logback.xml"}'
For containers, the operation takes the container body: id is always container with custom: false, and version is any existing version, for example template.latestVersion from the container detail or list.
The operation writes nothing. To get scaffold files into the repository, put their paths into the change's includePaths, so they are committed to the new branch, or apply them by hand.
Examples
The examples use $API for https://api.cloud.codenow.com and $KEY for your API key. Each change returns {template, branch}; merge the branch it names into the default branch to finish the change in the repository.
Move an Application Component to the Latest Version
Read the component, then preview the change with its template.id and template.custom and template.latestVersion. In advanced mode, include the Dockerfile and Helm files the preview marks selectable:
curl -X POST "$API/applications/$APP_ID/components/$COMPONENT_ID/template/preview" \
-H "X-Codenow-Api-Key: $KEY" \
-H "Content-Type: application/vnd.codenow.v1+json" \
-H "Accept: application/vnd.codenow.v1+json" \
-d '{"id": "java-maven-micronaut", "custom": false, "version": "3.4.0", "includePaths": ["Dockerfile"]}'
Check the effects and outcome (branchExists must be false), then send the same body to the change:
curl -X PUT "$API/applications/$APP_ID/components/$COMPONENT_ID/template" \
-H "X-Codenow-Api-Key: $KEY" \
-H "Content-Type: application/vnd.codenow.v1+json" \
-H "Accept: application/vnd.codenow.v1+json" \
-d '{"id": "java-maven-micronaut", "custom": false, "version": "3.4.0", "includePaths": ["Dockerfile"]}'
{
"template": { "id": "java-maven-micronaut", "name": "Java Maven Micronaut", "custom": false, "version": "3.4.0", "latestVersion": "3.4.0", "outdated": false },
"branch": {
"name": "codenow/change-template-orders-java-maven-micronaut-3.4.0",
"baseBranch": "main",
"baseCommit": "3f2c1a9",
"commit": "8d04b7e",
"paths": [".codenow.yaml", "Dockerfile"],
"webUrl": null
}
}
The component is on version 3.4.0 now. Review the branch named in branch.name in the repository and merge it into main. Libraries (…/libraries/{libraryId}/template) and agents (…/agent-swarms/{agentSwarmId}/agents/{agentId}/template) work the same way.
When branch is null, nothing had to be committed and no branch was created; the template change itself is done and there is nothing to merge. The preview showed this beforehand as outcome.branch: null.
Change the Version of a Container
Containers have a single platform template, so only the version can change. The body is fixed apart from the version and the files: any version from /templates/container/versions?custom=false, for example template.latestVersion from the container detail or list. A container's Dockerfile is always in the repository, so include it if you want the new template's version on the branch:
curl -X PUT "$API/containers/$CONTAINER_ID/template" \
-H "X-Codenow-Api-Key: $KEY" \
-H "Content-Type: application/vnd.codenow.v1+json" \
-H "Accept: application/vnd.codenow.v1+json" \
-d '{"id": "container", "custom": false, "version": "1.6.0", "includePaths": ["Dockerfile"]}'
Switch to a Specific Version of a Template
This works the same for platform and custom templates; the example uses a custom one.
-
List the versions of the template (newest first; an unknown template returns
[]):curl "$API/templates/my-java-service/versions?custom=true" \-H "X-Codenow-Api-Key: $KEY" -H "Accept: application/vnd.codenow.v1+json"[{ "version": "2.1.0", "latest": true },{ "version": "2.0.0", "latest": false },{ "version": "1.4.0", "latest": false }] -
Read the properties of the version you want, because they can differ from the latest version's. Omit
versionto get the latest. An unknown template returns 404.curl "$API/templates/my-java-service?custom=true&version=2.0.0" \-H "X-Codenow-Api-Key: $KEY" -H "Accept: application/vnd.codenow.v1+json"{"id": "my-java-service","version": "2.0.0","custom": true,"properties": [{ "name": "javaVersion", "description": "Java version", "type": "string", "required": true }]} -
Preview, then change the resource with the same body. Send only the properties you want to change; required properties the resource already has a value for need not be sent. Without
includePaths, the branch holds only.codenow.yaml.curl -X PUT "$API/libraries/$LIBRARY_ID/template" \-H "X-Codenow-Api-Key: $KEY" \-H "Content-Type: application/vnd.codenow.v1+json" \-H "Accept: application/vnd.codenow.v1+json" \-d '{"id": "my-java-service", "custom": true, "version": "2.0.0", "properties": {"javaVersion": "17"}}' -
Merge the branch named in the response.
Move Many Resources to the Latest Version
The template block is on list responses, so a batch change needs no detail calls: list → keep template.outdated == true → preview and change each with {id: template.id, custom: template.custom, version: template.latestVersion}. Every change creates its own branch in the resource's repository, so a batch leaves one branch per resource to review and merge. Example for all application components of an application, using jq (preview calls left out for brevity; without includePaths each branch holds only .codenow.yaml):
curl -s "$API/applications/$APP_ID/components" \
-H "X-Codenow-Api-Key: $KEY" -H "Accept: application/vnd.codenow.v1+json" \
| jq -c '.[] | select(.template.outdated == true)
| {cid: .id, body: {id: .template.id, custom: .template.custom, version: .template.latestVersion}}' \
| while read -r item; do
cid=$(jq -r .cid <<<"$item")
curl -s -X PUT "$API/applications/$APP_ID/components/$cid/template" \
-H "X-Codenow-Api-Key: $KEY" \
-H "Content-Type: application/vnd.codenow.v1+json" \
-H "Accept: application/vnd.codenow.v1+json" \
-d "$(jq -c .body <<<"$item")" \
| jq -r --arg cid "$cid" '
if .status then "\($cid): HTTP \(.status) \(.parameters.errorId // "")"
elif .branch then "\($cid): merge \(.branch.name)"
else "\($cid): changed, nothing to merge" end'
done
template.custom is always false here, because only platform templates are reported as outdated. The same pattern works for GET /libraries, GET /containers and GET /agent-swarms/{agentSwarmId}/agents. Errors affect only their own item:
- 409
E7013— a build of the resource is running; retry it after the build finishes. - 409
E7019— the branch already exists in that repository, for example from an earlier run. Merge or delete the branch, then repeat that item.
Resources that share one repository (a monorepo) don't get in each other's way: the resource id is part of the branch name, so the batch creates one distinct branch per resource.
The resources switch to the new template one by one as their changes succeed, independently of when you merge their branches.
Error Reference
The same responses apply to all four change operations and, except E7013, E7015, E7016 and E7019, to the preview and preview file operations. E7017 is returned only by the preview file operations, E7018 only by the change and the preview. E7020 is returned by all of them. Coded errors are returned as application/problem+json. The error code and its key/value context are nested under parameters: parameters.errorId and parameters.context. type is always https://api.codenow.com/problem/exception, title is the HTTP reason phrase and detail is a human-readable message.
{
"type": "https://api.codenow.com/problem/exception",
"title": "Conflict",
"status": 409,
"detail": "The template cannot be changed while a build of this resource is running. Wait for the build to finish or cancel it, then try again.",
"parameters": {
"errorId": "E7013",
"context": [
{ "key": "appComponentId", "value": "my-lib" },
{ "key": "buildId", "value": "42" }
]
}
}
| HTTP | parameters.errorId | When | parameters.context keys | What to do |
|---|---|---|---|---|
| 400 | E7011 | The template is not valid for this resource kind: it is not offered when creating a resource of the same kind, or the id does not exist with the given custom value. | templateId, customTemplate, resourceType | Pick a template from the creation listing of that kind; check custom. |
| 400 | E7001 | The version does not exist. | id, version | Pick a version from /templates/{templateId}/versions. |
| 400 | E7017 | Preview file only: path is not a scaffold file of this preview, i.e. not one of its otherFiles paths. This includes .codenow.yaml, the Dockerfile and helm/ files, whose content is already in the preview. | path | Run the preview again with the same body and pick a path from its otherFiles. |
| 400 | E7018 | Change and preview: an includePaths entry is not a selectable path of the preview — not a files[].path with selectable: true nor an otherFiles[].path with symlink: false (this includes symbolic links in the repository, a path with a repository file at a parent path or a repository directory at the path itself, and paths that leave the resource root; naming .codenow.yaml is ignored). Nothing was changed. | path | Run the preview again and pick the paths from it. |
| 400 | E7020 | The target template itself cannot be rendered. The detail names the template, the file and the line. Nothing was changed. | templateId, version, path | Don't retry and don't vary properties: tell the user. |
| 409 | E7013 | A build of the resource is running (change only, never the preview). Nothing was changed. | appComponentId, buildId | Wait for the build to finish or cancel it, then retry. |
| 409 | E7019 | The branch the change would create already exists (change only; the preview shows it as outcome.branchExists). It is never overwritten, and this call changed nothing. After a lost answer, though, the earlier call may have created the branch and switched the template. Not returned when nothing would be committed: then no branch is created and the check is skipped. | appComponentId, branch | Merge or delete the branch in the repository, then repeat the change. After a lost answer, first read the resource's template and look at the branch. |
| 502 | E7014 | The repository's default branch could not be read, or the SCM provider or repository could not be resolved (preview, or change before anything was written). Also returned when the resource's own path in the repository runs through a symbolic link: such a resource is refused. Nothing was changed. | appComponentId | Retry later, or check the resource's SCM settings if it persists. For a symbolic link in the resource's path, retrying does not help: replace the link with a real directory. |
| 502 | E7015 | The branch could not be created. CodeNOW creates the branch first and only then switches the template, so nothing was changed. | appComponentId, branch | Retry later. |
| 500 | E7016 | The branch was created, but switching the template failed and the branch could not be removed again. The resource is still on its old template. This is the only case in which a change is left half done. | appComponentId, branch | Don't retry automatically: while the branch exists, a retry fails with E7019. Tell the user to delete the branch named in branch, then repeat the change. |
| 400 | — | A template property failed validation (same rules as on creation), or the resource is not ready (creation in progress or failed). | — | Read detail. Fix the property value. A failed resource must be deleted and created again. |
| 403 | — | You don't have update permission on the resource. | — | Request update permission. |
| 404 | — | The resource does not exist, including an id that belongs to another parent or another kind. Nothing was changed. The body is application/problem+json (schema Problem) without parameters.errorId. | — | Check the ids in the path. |
| 502 | — | Change: the connection to CodeNOW dropped before it confirmed the change; the change may still have completed. Preview, preview file: the answer is larger than the API passes on; nothing was changed. | — | Change: see Lost Answer. Otherwise retry later or narrow the request. |
| 504 | — | CodeNOW did not answer in time. Change: the change may still have completed. Preview, preview file: nothing was changed. | — | Change: see Lost Answer. Otherwise retry later. |
If a Change Call Times Out
If a change call answers 504, answers 502 without an errorId, or the connection drops, you don't know whether the change happened. It may still have completed: the template is switched and the branch exists. Don't repeat the call blindly:
- Read the resource and check its
template. - Look for the branch in the repository (its name is the preview's
outcome.branch). - If both show the change, it is done: review and merge the branch. If neither does, repeat the change.
A repeated call after a completed change answers 409 E7019, because the branch now exists. In that situation E7019 does not mean that nothing changed.
detail messages of the coded errors:
parameters.errorId | detail | Example |
|---|---|---|
E7011 | Template {templateId} is not a valid template for resource type {resourceType} | Template java-spring-boot is not a valid template for resource type library |
E7001 | No template found for {templateId}/{version} | No template found for java-spring/9.9.9 |
E7013 | Fixed text | The template cannot be changed while a build of this resource is running. Wait for the build to finish or cancel it, then try again. |
resourceType is one of application_component, agent, library or container. For E7014, E7015, E7016, E7018, E7019 and E7020 the detail is a short message from the platform. Program against parameters.errorId and parameters.context, not against the detail wording.
The code E7001 is also used by an unrelated error of other operations (for example merging a merge request). Interpret an error code together with the operation that returned it.
The context key is named appComponentId for all resource kinds (library, container and agent too), so it holds whichever resource the request was for.
Via MCP
The MCP server exposes the preview, the scaffold file content and the change as eleven tools:
| Tool | Arguments |
|---|---|
application_components_template_change | applicationId, applicationComponentId, id, version, custom, properties?, includePaths? |
library_template_change | libraryId, id, version, custom, properties?, includePaths? |
container_template_change | containerId, id, version, custom, properties?, includePaths? |
application_components_template_preview | same as application_components_template_change |
library_template_preview | same as library_template_change |
container_template_preview | same as container_template_change |
application_components_template_preview_file | same as application_components_template_preview without includePaths, plus path |
library_template_preview_file | same as library_template_preview without includePaths, plus path |
container_template_preview_file | same as container_template_preview without includePaths, plus path |
templates_versions_list | templateId, custom |
templates_get | templateId, custom, version? |
? marks optional arguments. All arguments are flat, top-level tool arguments, named as in the REST API. The meanings and rules are the same as above. For containers the template is always id: "container", custom: false; version can be any published version.
Agents are not available through the MCP server yet. Change an agent's template through the REST API or the Portal.
- Results are the API's JSON body unchanged:
{template, branch}for the change tools (see The Change Response), the version list, or the template detail. The preview and preview file tools are the exception: the MCP server decodes the base64currentandtargetfile contents to text for the model. The preview tools reduce anIDENTICALpair to just itsresult; the preview file tools return the pair in full, since the file was asked for. For a binary file, the preview file result has novsRepositoryand carriesnote: "Binary file: its content cannot be shown."application_components_list/_get,library_list/_getandcontainer_list/_getreturn thetemplateblock too. - Errors: the tool descriptions do not list the error codes. A failed call returns a tool result marked as an error, with the text
CodeNOW API error: <status> <statusText> - <response body>. For coded errors the body is the problem+json shown in Error Reference, with the code inparameters.errorIdand the details inparameters.context. The codes are therefore only visible in that body, at call time. A missing required argument (for examplecustom) is rejected by the MCP server before any API call.
Preview first. The tool descriptions guide an assistant through the same flow as above: call the preview tool and show you the effects by actor, fetch scaffold files with the preview file tool where it needs their content, ask you which files to include in the branch, preview again with them in includePaths to see the outcome, and only then call the change tool. Afterwards it tells you the name of the new branch, which you review and merge. So you know before anything happens that the resource switches at once, which files go into the branch and what is left for you.
Batch changes with an AI assistant. The tool descriptions already contain the batch pattern, so you can ask in plain language, for example:
Move all outdated application components in application orders to their latest template version.
The assistant lists the components, keeps those with template.outdated == true, previews and calls application_components_template_change for each with id = template.id, custom = template.custom, version = template.latestVersion and the files you chose. No detail calls are needed. You get one branch per component to merge.