# Update workflow template

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Replaces the contents of a workflow template. The interface is updated as fully defined; fields to be retained should also be provided in the request.

```text
PUT https://moi.matrixorigin.cn/newmoi/workflow-templates/{id}
```

## Preparation before calling

First [query workflow template details](get-workflow-template.md) to obtain the current complete definition; the fields to be retained should be copied to this request. Prepare a personal access token and target workspace ID that has access to the target workspace. Updating built-in templates also requires administrator rights.


## Request body

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>name</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The updated template name. Custom templates cannot have the same name in the current workspace and language.</dd></div>
  <div class="mo-api-field"><dt><code>description</code><span class="mo-api-field__type">string</span></dt><dd>Updated template description; this field will be cleared if not passed.</dd></div>
  <div class="mo-api-field"><dt><code>dsl_yaml</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>Updated workflow DSL YAML.</dd></div>
  <div class="mo-api-field"><dt><code>runtime_fields</code><span class="mo-api-field__type">string</span></dt><dd>The updated runtime field JSON text; if not passed, the field will be cleared. Must be valid JSON when provided.</dd></div>
  <div class="mo-api-field"><dt><code>is_builtin</code><span class="mo-api-field__type">boolean</span></dt><dd>Template type cannot be changed. When updating a custom template set to true, it will be rejected; the permissions of the built-in template are verified by the server based on the original template type.</dd></div>
  <div class="mo-api-field"><dt><code>template_key</code><span class="mo-api-field__type">string</span></dt><dd>Can be omitted to retain the original value when updating a built-in template; it is ignored and cleared in custom templates. It cannot be used to change the template type.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Request example</p>
```

```bash
curl -X PUT "https://moi.matrixorigin.cn/newmoi/workflow-templates/$TEMPLATE_ID" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "<TEMPLATE_NAME>",
    "description": "<DESCRIPTION>",
    "dsl_yaml": "<WORKFLOW_DSL_YAML>",
    "runtime_fields": "{\"fields\":[]}",
    "is_builtin": false
  }'
```

:::
::::

## Successful response

Returns `200` on success. `data` is the updated complete template object.


The response fields are as follows.

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">string</span></dt><dd>OK when successful.</dd></div>
  <div class="mo-api-field"><dt><code>msg</code><span class="mo-api-field__type">string</span></dt><dd>OK when successful.</dd></div>
  <div class="mo-api-field"><dt><code>data.id</code><span class="mo-api-field__type">integer</span></dt><dd>Template ID.</dd></div>
  <div class="mo-api-field"><dt><code>data.workspace_id</code><span class="mo-api-field__type">string</span></dt><dd>The ID of the workspace to which it belongs; the built-in template is an empty string.</dd></div>
  <div class="mo-api-field"><dt><code>data.created_by</code><span class="mo-api-field__type">string</span></dt><dd>Creator ID.</dd></div>
  <div class="mo-api-field"><dt><code>data.updated_by</code><span class="mo-api-field__type">string</span></dt><dd>Last updater ID.</dd></div>
  <div class="mo-api-field"><dt><code>data.template_key</code><span class="mo-api-field__type">string</span></dt><dd>Built-in template identifier; custom template is an empty string.</dd></div>
  <div class="mo-api-field"><dt><code>data.name</code><span class="mo-api-field__type">string</span></dt><dd>The updated name.</dd></div>
  <div class="mo-api-field"><dt><code>data.description</code><span class="mo-api-field__type">string</span></dt><dd>Updated description.</dd></div>
  <div class="mo-api-field"><dt><code>data.language</code><span class="mo-api-field__type">string</span></dt><dd>Template language.</dd></div>
  <div class="mo-api-field"><dt><code>data.dsl_yaml</code><span class="mo-api-field__type">string</span></dt><dd>Updated workflow DSL YAML.</dd></div>
  <div class="mo-api-field"><dt><code>data.runtime_fields</code><span class="mo-api-field__type">string</span></dt><dd>Updated runtime field JSON text.</dd></div>
  <div class="mo-api-field"><dt><code>data.is_builtin</code><span class="mo-api-field__type">boolean</span></dt><dd>The original type of the template.</dd></div>
  <div class="mo-api-field"><dt><code>data.created_at</code><span class="mo-api-field__type">string</span></dt><dd>Creation time; may be omitted if not provided by the server.</dd></div>
  <div class="mo-api-field"><dt><code>data.updated_at</code><span class="mo-api-field__type">string</span></dt><dd>Last updated time; may be omitted if not provided by the server.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Successful response example</p>
```

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "id": 12,
    "workspace_id": "ws-001",
    "created_by": "user-001",
    "updated_by": "user-002",
    "template_key": "",
    "name": "daily-import-template",
    "description": "更新后的每日导入工作流模板",
    "language": "zh-CN",
    "dsl_yaml": "workflow: {}",
    "runtime_fields": "{\"fields\":[]}",
    "is_builtin": false,
    "created_at": "2026-08-18T10:00:00Z",
    "updated_at": "2026-08-18T11:00:00Z"
  }
}
```

:::
::::

## Error response

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">string</span></dt><dd>Error code.</dd></div>
  <div class="mo-api-field"><dt><code>msg</code><span class="mo-api-field__type">string</span></dt><dd>Readable error message.</dd></div>
  <div class="mo-api-field"><dt><code>data</code><span class="mo-api-field__type">null</span></dt><dd>`null` in an error response.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Error response example</p>
```

```json
{
  "code": "ErrTemplateTypeImmutable",
  "msg": "不能修改模板类型",
  "data": null
}
```

:::
::::

## Follow-up operations

[Query workflow template details](get-workflow-template.md) confirms the update result.
