Skip to main content

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 in includePaths. 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.yaml and 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.yaml or 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
}
FieldMeaning
idTemplate id. Send it back as id in a change request.
nameHuman-readable name; null when the referenced version no longer exists.
customtrue 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.
versionThe version the resource is on.
latestVersionThe newest available version, for custom templates too; null when no version is available any more.
outdatedtrue 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
}
}
FieldMeaning
templateThe resource's template after the change. The resource already uses it.
branchThe new branch, or null when there was nothing to commit (every included file already matched the repository); then no branch was created.
branch.nameThe name of the new branch. The preview's outcome.branch shows it before you confirm. See Branch Names.
branch.baseBranch, branch.baseCommitThe default branch and the commit the new branch starts from. Merge the new branch into baseBranch.
branch.commitThe single commit on the new branch.
branch.pathsThe paths the commit changes, relative to the resource root.
branch.webUrlReserved 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​

OperationEndpoint
Change the template of an application componentPUT /applications/{applicationId}/components/{applicationComponentId}/template
Change the template of a libraryPUT /libraries/{libraryId}/template
Change the template version of a containerPUT /containers/{containerId}/template
Change the template of an agentPUT /agent-swarms/{agentSwarmId}/agents/{agentId}/template
Preview a template change of an application componentPOST /applications/{applicationId}/components/{applicationComponentId}/template/preview
Preview a template change of a libraryPOST /libraries/{libraryId}/template/preview
Preview a template change of a containerPOST /containers/{containerId}/template/preview
Preview a template change of an agentPOST /agent-swarms/{agentSwarmId}/agents/{agentId}/template/preview
Read a scaffold file of a template change preview of an application componentPOST /applications/{applicationId}/components/{applicationComponentId}/template/preview/file
Read a scaffold file of a template change preview of a libraryPOST /libraries/{libraryId}/template/preview/file
Read a scaffold file of a template change preview of a containerPOST /containers/{containerId}/template/preview/file
Read a scaffold file of a template change preview of an agentPOST /agent-swarms/{agentSwarmId}/agents/{agentId}/template/preview/file
List versions of a templateGET /templates/{templateId}/versions?custom=
Get a template versionGET /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"]
}
FieldRequiredMeaning
idyesTarget 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.
versionyesTarget version: any version from /templates/{templateId}/versions, for platform and custom templates alike.
customyestrue 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.
propertiesnoTemplate 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.
includePathsnoChange 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:

  1. Call the preview with the target id, version, custom and any properties.
  2. Show or check the effects (PLATFORM effects happen automatically, USER effects are left to you) and the diffs in files. Read scaffold files on demand with preview/file.
  3. Choose which files go into the branch: any files[] entry with selectable: true and any otherFiles[] entry. Call the preview again with them in includePaths to see the resulting outcome and effects.
  4. If outcome.branchExists is false, call the change with the same body.
  5. 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 head commit, which the preview was computed against. There is no lock: the branch may move before you confirm. advancedMode is true or false as set by advancedMode.enabled in that branch's .codenow.yaml, and null when the target template declares no advanced mode setting (for example docker-generic, helm-generic and other runnable templates, libraries and containers). Which files you have to handle is decided per file by managedBy, not by this flag.

  • files — the files CodeNOW manages: .codenow.yaml, the Dockerfile and the helm/ 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 are REPOSITORY and carry only vsCurrentTemplate (old version compared with new version).

    • managedBy — PLATFORM when CodeNOW takes care of the file: .codenow.yaml always (merged and committed to the branch); the Dockerfile and Helm chart when advanced mode is off (rendered at the next build). REPOSITORY when the repository's copy is authoritative: the Dockerfile and Helm chart in advanced mode; for a runnable target template (for example docker-generic, helm-generic), for every kind, the Dockerfile and helm/ 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 on managedBy, never on advancedMode alone.
    • selectable — true when the path can go into includePaths: the new template renders it, it is managedBy: REPOSITORY and 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). false for .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 — true when 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 in includePaths answers 400 E7018.
    • 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) or OTHER_ONLY (only the current template or the repository has it). current and target are the file contents, base64-encoded, or null when the file doesn't exist on that side.
    • For .codenow.yaml, the vsRepository target is the merged file the change will commit to the branch. For any other file you include, the commit holds the target content as it is.
  • otherFiles — the application scaffold: every file the new template renders outside .codenow.yaml, the Dockerfile and the helm/ directory, by name only. inRepository tells whether a file of that name already exists, binary whether its content is not text (for example a Gradle wrapper JAR), and symlink whether 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 into includePaths (400 E7018). For a change to another version of the same template, these are the same files whose version comparison is in files. CodeNOW does not need them; each one that can be replaced in the repository (see includePaths above) can be put into includePaths, 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's includePaths would create:

    • branch — the name of the new branch (see Branch Names), or null when nothing would be committed;
    • branchExists — true when a branch of that name already exists. The change would then fail with 409 E7019; merge or delete that branch first, then preview again. false when branch is null: 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, branch is null and paths is empty: confirming only switches the template, creates no branch, and there is nothing to merge.

  • effects — the consequences, each with a code, an actor and an end-user message. Key on code, 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.yaml key, for example runtime.image, or build.pipelines.release.pipeline / build.pipelines.preview.pipeline for pipelines;
    • previousValue — the value in the default branch's .codenow.yaml before the change, only when it changes or the key is removed;
    • value — the value after the change; for PIPELINE_KEPT, PIPELINE_DEFAULT_KEPT, CI_PROPERTY_KEPT and CI_PROPERTY_DEFAULT_KEPT, the unchanged value; omitted when the key is removed;
    • defaultValue — the new template's default for key, never the previous template's; omitted when it has none.

    Every pipeline effect (PIPELINE_…) and CI setting effect (CI_PROPERTY_…) carries key, the dotted .codenow.yaml path, plus the fields named in its row of the table below. Effects outside these two families carry none of the four fields.

actorcodeMeaning
PLATFORMBRANCH_CREATEDThe new branch will be created with one commit holding .codenow.yaml and the included files.
PLATFORMCODENOW_YAML_MERGED.codenow.yaml will be merged and committed to the new branch.
PLATFORMCODENOW_YAML_ABSENTThe repository has no .codenow.yaml; it is not part of the commit.
PLATFORMPIPELINE_CHANGEDA pipeline still at the old template's default will be switched to the new template's default. key, previousValue → value.
PLATFORMPIPELINE_DEFAULT_KEPTA pipeline equal to the previous template's default is kept, because the new template has none. key, value.
PLATFORMCI_PROPERTY_CHANGEDA CI setting still at the old template's default will follow the new template's default. key, previousValue → value, defaultValue.
PLATFORMCI_PROPERTY_ADDEDA CI setting the current template doesn't declare will be added with the new template's default. key, value, defaultValue.
PLATFORMCI_PROPERTY_DROPPEDA CI setting the new template no longer declares will be removed. key, previousValue.
PLATFORMCI_PROPERTY_DEFAULT_KEPTA CI setting equal to the previous template's default is kept, because the new template has none. key, value.
PLATFORMCI_FILES_RENDERED_AT_NEXT_BUILDThe Dockerfile and Helm chart will be rendered from the new template at the next build (advanced mode off).
PLATFORMCURRENT_TEMPLATE_UNAVAILABLEThe current template version is no longer available, so vsCurrentTemplate is omitted.
USERMERGE_BRANCHReview the new branch and merge it into the default branch.
USERBRANCH_EXISTSThe branch already exists. Merge or delete it before you confirm.
USERTEMPLATE_SWITCHED_BEFORE_MERGEThe 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.
USERAPPLY_REPOSITORY_CHANGESChanged 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.
USERCODENOW_YAML_NOT_MERGEDThe repository's .codenow.yaml could not be parsed. CodeNOW leaves it as it is; adapt it to the new template by hand.
USERPIPELINE_KEPTA 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).
USERCI_PROPERTY_KEPTA 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).
USEROTHER_TEMPLATE_FILESThe 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.target is the file rendered from the new template with the resource's properties; current is the default branch's copy when inRepository is true, otherwise null and result is TARGET_ONLY.
  • For a binary file (binary: true: it contains a NUL byte or is not valid UTF-8), vsRepository is omitted: the content of a binary file is not returned. To get the file into the repository, include its path in includePaths so 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.

  1. 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 }
    ]
  2. Read the properties of the version you want, because they can differ from the latest version's. Omit version to 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 }
    ]
    }
  3. 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"}}'
  4. 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" }
]
}
}
HTTPparameters.errorIdWhenparameters.context keysWhat to do
400E7011The 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, resourceTypePick a template from the creation listing of that kind; check custom.
400E7001The version does not exist.id, versionPick a version from /templates/{templateId}/versions.
400E7017Preview 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.pathRun the preview again with the same body and pick a path from its otherFiles.
400E7018Change 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.pathRun the preview again and pick the paths from it.
400E7020The target template itself cannot be rendered. The detail names the template, the file and the line. Nothing was changed.templateId, version, pathDon't retry and don't vary properties: tell the user.
409E7013A build of the resource is running (change only, never the preview). Nothing was changed.appComponentId, buildIdWait for the build to finish or cancel it, then retry.
409E7019The 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, branchMerge 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.
502E7014The 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.appComponentIdRetry 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.
502E7015The branch could not be created. CodeNOW creates the branch first and only then switches the template, so nothing was changed.appComponentId, branchRetry later.
500E7016The 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, branchDon'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:

  1. Read the resource and check its template.
  2. Look for the branch in the repository (its name is the preview's outcome.branch).
  3. 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.errorIddetailExample
E7011Template {templateId} is not a valid template for resource type {resourceType}Template java-spring-boot is not a valid template for resource type library
E7001No template found for {templateId}/{version}No template found for java-spring/9.9.9
E7013Fixed textThe 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.

note

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.

note

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:

ToolArguments
application_components_template_changeapplicationId, applicationComponentId, id, version, custom, properties?, includePaths?
library_template_changelibraryId, id, version, custom, properties?, includePaths?
container_template_changecontainerId, id, version, custom, properties?, includePaths?
application_components_template_previewsame as application_components_template_change
library_template_previewsame as library_template_change
container_template_previewsame as container_template_change
application_components_template_preview_filesame as application_components_template_preview without includePaths, plus path
library_template_preview_filesame as library_template_preview without includePaths, plus path
container_template_preview_filesame as container_template_preview without includePaths, plus path
templates_versions_listtemplateId, custom
templates_gettemplateId, 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

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 base64 current and target file contents to text for the model. The preview tools reduce an IDENTICAL pair to just its result; the preview file tools return the pair in full, since the file was asked for. For a binary file, the preview file result has no vsRepository and carries note: "Binary file: its content cannot be shown." application_components_list / _get, library_list / _get and container_list / _get return the template block 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 in parameters.errorId and the details in parameters.context. The codes are therefore only visible in that body, at call time. A missing required argument (for example custom) 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.