---
title: "创建或修改主题文件"
description: "创建或修改指定主题资产文件的内容，如果所修改的主题资产文件不存在，则根据传入的信息创建新的主题资产文件。"
doc_type: openapi
doc_category: openapi
doc_version: v20270301
source_url:
  html: 'https://developer.shopline.com/zh-hans-cn/docs/admin-rest-api/online-store/asset/create-or-update-a-theme-file'
  md: 'https://developer.shopline.com/zh-hans-cn/docs/admin-rest-api/online-store/asset/create-or-update-a-theme-file.md'
---
# 创建或修改主题文件

创建或修改指定主题资产文件的内容，如果所修改的主题资产文件不存在，则根据传入的信息创建新的主题资产文件。

- **Base URL:** `https://{handle}.myshopline.com/admin/openapi`
- **Required Scopes:** `write_themes`
- **API Version:** v20270301
- **API Type:** Admin
- **API Protocol:** RESTful

## Endpoint

```http
PUT /themes/:theme_id/assets.json
```

## Base URL

* `https://{handle}.myshopline.com/admin/openapi`

  * `{handle}`: `handle` ：店铺的唯一标识符，值为店铺域名的前缀。例如，域名为 `open001.myshopline.com` 的店铺，其 `handle` 是 `open001` 。

## Required Permissions

* `write_themes`

## Request

### Path Parameters

* `theme_id`

  string (required)

  主题的唯一标识 ID。

### Request Headers

* `Content-Type`

  string (required)

  字段值固定为 `application/json; charset=utf-8`。

* `Authorization`

  string (required)

  资源的访问令牌。参考 [应用授权](https://developer.shopline.com/zh-hans-cn/docs/apps/api-instructions-for-use/app-authorization.md?lang=zh-hans-cn) 获取访问令牌，然后将获取到的访问令牌以 Bearer 格式传入。

### Request Body

* `asset`

  object

  需要创建或修改的主题资产文件信息。`value`、`src`、`attachment`、`source_key` 四个字段只能选择其中一个传入，不能同时使用或全部为空。

  * `source_key`

    string

    被复制的现有主题资产文件名称。`value`、`src`、`attachment`、`source_key` 四个字段只能选择其中一个传入，不能同时使用或全部为空。

  * `src`

    string

    主题资产文件的下载地址。`value`、`src`、`attachment`、`source_key` 四个字段只能选择其中一个传入，不能同时使用或全部为空。

  * `value`

    string

    主题资产文件的文本内容。`value`、`src`、`attachment`、`source_key` 四个字段只能选择其中一个传入，不能同时使用或全部为空。

  * `attachment`

    string

    图片 base64 内容。格式：[base64](https://en.wikipedia.org/wiki/Base64)。`value`、`src`、`attachment`、`source_key` 四个字段只能选择其中一个传入，不能同时使用或全部为空。

  * `key`

    string

    需要创建或修改的主题资产文件的名称。

## Response

### Status Codes

* `200`

  更多状态码信息，参考 [HTTP 状态码](https://developer.shopline.com/zh-hans-cn/docs/apps/api-instructions-for-use/http-status-code.md?lang=zh-hans-cn)。

* `401`

  

* `429`

  

### Response Headers

* `traceId`

  请求的全局唯一标识符。用于追踪请求在系统中的流转，以便于问题发生时进行定位和调试。

### Response Body

#### 200

* `asset`

  object

  主题资产文件的信息。

  * `public_url`

    string

    主题资产文件的公开 URL。

  * `size`

    integer

    主题资产文件的大小。单位：字节。

  * `theme_id`

    string

    主题的唯一标识 ID。

  * `updated_at`

    long

    主题资产文件的更新时间，格式为 13 位毫秒级时间戳。

  * `checksum`

    string

    主题资产文件的 MD5 校验值。格式：[MD5](https://en.wikipedia.org/wiki/MD5)。

  * `content_type`

    string

    主题资产文件的 MIME 类型，包括一个类型和子类型，表示文件的类型和格式。格式：[MIME](https://en.wikipedia.org/wiki/Media_type)。

  * `created_at`

    long

    主题资产文件的创建时间，格式为 13 位毫秒级时间戳。

  * `key`

    string

    主题资产文件的名称。

* `check_errors`

  array<object>

  校验错误结果。

  * `filename`

    string

    出错的文件名称。

  * `message`

    array<string>

    错误信息。

  * `type`

    string

    错误类型。


#### 401

* `errors`

  string

  错误描述。


#### 429

* `errors`

  string

  错误描述。


## OpenAPI Definition

```json
{
  "tags": [
    "创建或修改主题文件"
  ],
  "description": "创建或修改指定主题资产文件的内容，如果所修改的主题资产文件不存在，则根据传入的信息创建新的主题资产文件。",
  "externalDocs": {
    "description": "接口使用的权限点: `write_themes` ，更多权限点使用信息，请参考:",
    "url": "ec20/3cv5d7wpfgr6a8z5/xabczf5442284vkq?lang=zh-hans-cn",
    "errorTableDescription": ""
  },
  "operationId": "nrtLU7Mw",
  "parameters": [
    {
      "name": "theme_id",
      "in": "path",
      "description": "主题的唯一标识 ID。",
      "required": true,
      "style": "simple",
      "schema": {
        "name": "theme_id",
        "description": "主题的唯一标识 ID。",
        "type": "string"
      },
      "examples": {
        "创建或修改主题文件": {
          "value": "6388827102b701028efac460"
        }
      }
    },
    {
      "name": "Content-Type",
      "in": "header",
      "description": "字段值固定为 `application/json; charset=utf-8`。",
      "required": true,
      "schema": {
        "name": "Content-Type",
        "type": "string",
        "example": "application/json; charset=utf-8"
      }
    },
    {
      "name": "Authorization",
      "in": "header",
      "description": "资源的访问令牌。参考 [应用授权](https://developer.shopline.com/zh-hans-cn/docs/apps/api-instructions-for-use/app-authorization.md?lang=zh-hans-cn) 获取访问令牌，然后将获取到的访问令牌以 Bearer 格式传入。",
      "required": true,
      "style": "string",
      "schema": {
        "name": "Authorization",
        "description": "资源的访问令牌。参考 [应用授权](https://developer.shopline.com/zh-hans-cn/docs/apps/api-instructions-for-use/app-authorization.md?lang=zh-hans-cn) 获取访问令牌，然后将获取到的访问令牌以 Bearer 格式传入。",
        "type": "string",
        "example": "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MCwiYXBwS2V5IjoiNzU2ZjI1NWE2NjdlZTcwNTk1MzM0ZjVjYzk4NzU5MzBmN2E3NGZjMSIsImV4cCI6MTg3OTQ4MjA3NiwiaXNzIjoieXNvdWwiLCJzZWxsZXJJZCI6IjIwMDAyMzQ4ODAiLCJzdG9yZUlkIjoiMTY3MjM2OTcyOTYwNiIsInRpbWVzdGFtcCI6MTc4NDc4NzY3NjY2MSwidmVyc2lvbiI6IlYyIn0.3ZzbGAH4cLU1QR2VPEvMOQInUDvus-C4amkINSQIPuNVlXsFKj0sAt1c0KnUy9MWUOFV9cHlkf7J90r2y1FzpA"
      },
      "example": "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MCwiYXBwS2V5IjoiNzU2ZjI1NWE2NjdlZTcwNTk1MzM0ZjVjYzk4NzU5MzBmN2E3NGZjMSIsImV4cCI6MTg3OTQ4MjA3NiwiaXNzIjoieXNvdWwiLCJzZWxsZXJJZCI6IjIwMDAyMzQ4ODAiLCJzdG9yZUlkIjoiMTY3MjM2OTcyOTYwNiIsInRpbWVzdGFtcCI6MTc4NDc4NzY3NjY2MSwidmVyc2lvbiI6IlYyIn0.3ZzbGAH4cLU1QR2VPEvMOQInUDvus-C4amkINSQIPuNVlXsFKj0sAt1c0KnUy9MWUOFV9cHlkf7J90r2y1FzpA"
    }
  ],
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "name": "body",
          "description": "body位置参数",
          "type": "object",
          "properties": {
            "asset": {
              "name": "asset",
              "description": "需要创建或修改的主题资产文件信息。`value`、`src`、`attachment`、`source_key` 四个字段只能选择其中一个传入，不能同时使用或全部为空。",
              "type": "object",
              "properties": {
                "source_key": {
                  "name": "source_key",
                  "description": "被复制的现有主题资产文件名称。`value`、`src`、`attachment`、`source_key` 四个字段只能选择其中一个传入，不能同时使用或全部为空。",
                  "type": "string",
                  "example": "assets/original-image-store-close.png"
                },
                "src": {
                  "name": "src",
                  "description": "主题资产文件的下载地址。`value`、`src`、`attachment`、`source_key` 四个字段只能选择其中一个传入，不能同时使用或全部为空。",
                  "type": "string",
                  "example": "https://cdn-theme.myshopline.com/cdn/shop/prev/example/example/assets/component-blog.css"
                },
                "value": {
                  "name": "value",
                  "description": "主题资产文件的文本内容。`value`、`src`、`attachment`、`source_key` 四个字段只能选择其中一个传入，不能同时使用或全部为空。",
                  "type": "string",
                  "example": "<p>an example</p>"
                },
                "attachment": {
                  "name": "attachment",
                  "description": "图片 base64 内容。格式：[base64](https://en.wikipedia.org/wiki/Base64)。`value`、`src`、`attachment`、`source_key` 四个字段只能选择其中一个传入，不能同时使用或全部为空。",
                  "type": "string",
                  "example": "base64_content"
                },
                "key": {
                  "name": "key",
                  "description": "需要创建或修改的主题资产文件的名称。",
                  "type": "string",
                  "example": "assets/copied-image-store-close.png"
                }
              },
              "required": [
                "key"
              ],
              "example": {
                "attachment": "base64_content",
                "key": "assets/copied-image-store-close.png",
                "source_key": "assets/original-image-store-close.png",
                "src": "https://cdn-theme.myshopline.com/cdn/shop/prev/example/example/assets/component-blog.css",
                "value": "<p>an example</p>"
              }
            }
          },
          "required": [
            "asset"
          ],
          "example": {
            "asset": {
              "src": "https://cdn-theme.myshopline.com/cdn/shop/prev/example/example/assets/component-blog.css",
              "value": "<p>an example</p>",
              "attachment": "base64_content",
              "key": "assets/copied-image-store-close.png",
              "source_key": "assets/original-image-store-close.png"
            }
          }
        },
        "examples": {
          "创建或修改主题文件": {
            "description": "创建或修改主题文件",
            "value": {
              "body": {
                "asset": {
                  "key": "sections/my-custom.html",
                  "value": "<div> custom section </div>"
                }
              },
              "path": {
                "theme_id": "6388827102b701028efac460"
              }
            }
          }
        }
      }
    },
    "required": true
  },
  "responses": {
    "200": {
      "description": "更多状态码信息，参考 [HTTP 状态码](https://developer.shopline.com/zh-hans-cn/docs/apps/api-instructions-for-use/http-status-code.md?lang=zh-hans-cn)。",
      "headers": {
        "traceId": {
          "description": "请求的全局唯一标识符。用于追踪请求在系统中的流转，以便于问题发生时进行定位和调试。"
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "name": "body",
            "type": "object",
            "properties": {
              "asset": {
                "name": "asset",
                "description": "主题资产文件的信息。",
                "type": "object",
                "properties": {
                  "public_url": {
                    "name": "public_url",
                    "description": "主题资产文件的公开 URL。",
                    "type": "string",
                    "example": "https://cdn-theme.myshopline.com/cdn/shop/prev/example/example/assets/component-blog.css"
                  },
                  "size": {
                    "name": "size",
                    "description": "主题资产文件的大小。单位：字节。",
                    "type": "integer",
                    "example": 204800
                  },
                  "theme_id": {
                    "name": "theme_id",
                    "description": "主题的唯一标识 ID。",
                    "type": "string",
                    "example": "671f4c96d2682a1f5407536e"
                  },
                  "updated_at": {
                    "name": "updated_at",
                    "description": "主题资产文件的更新时间，格式为 13 位毫秒级时间戳。",
                    "type": "long",
                    "example": 1625688873000
                  },
                  "checksum": {
                    "name": "checksum",
                    "description": "主题资产文件的 MD5 校验值。格式：[MD5](https://en.wikipedia.org/wiki/MD5)。",
                    "type": "string",
                    "example": "21cd91752e4cb57fda60099becd5ce3a224fc7fe62ba7409233a5dc5ab9556ce"
                  },
                  "content_type": {
                    "name": "content_type",
                    "description": "主题资产文件的 MIME 类型，包括一个类型和子类型，表示文件的类型和格式。格式：[MIME](https://en.wikipedia.org/wiki/Media_type)。",
                    "type": "string",
                    "example": "application/json"
                  },
                  "created_at": {
                    "name": "created_at",
                    "description": "主题资产文件的创建时间，格式为 13 位毫秒级时间戳。",
                    "type": "long",
                    "example": 1625688873000
                  },
                  "key": {
                    "name": "key",
                    "description": "主题资产文件的名称。",
                    "type": "string",
                    "example": "config/settings_data.json"
                  }
                },
                "example": {
                  "updated_at": 1625688873000,
                  "checksum": "21cd91752e4cb57fda60099becd5ce3a224fc7fe62ba7409233a5dc5ab9556ce",
                  "content_type": "application/json",
                  "created_at": 1625688873000,
                  "key": "config/settings_data.json",
                  "public_url": "https://cdn-theme.myshopline.com/cdn/shop/prev/example/example/assets/component-blog.css",
                  "size": 204800,
                  "theme_id": "671f4c96d2682a1f5407536e"
                }
              },
              "check_errors": {
                "name": "check_errors",
                "description": "校验错误结果。",
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "filename": {
                      "name": "filename",
                      "description": "出错的文件名称。",
                      "type": "string",
                      "example": "assets/blog.css"
                    },
                    "message": {
                      "name": "message",
                      "description": "错误信息。",
                      "type": "array",
                      "items": {
                        "type": "string",
                        "example": "error content"
                      },
                      "example": [
                        "error content"
                      ]
                    },
                    "type": {
                      "name": "type",
                      "description": "错误类型。",
                      "type": "string",
                      "example": "FILE"
                    }
                  },
                  "example": {
                    "filename": "assets/blog.css",
                    "message": [
                      "error content"
                    ],
                    "type": "FILE"
                  }
                },
                "example": [
                  {
                    "message": [
                      "error content"
                    ],
                    "type": "FILE",
                    "filename": "assets/blog.css"
                  }
                ]
              }
            },
            "example": {
              "asset": {
                "size": 204800,
                "theme_id": "671f4c96d2682a1f5407536e",
                "updated_at": 1625688873000,
                "checksum": "21cd91752e4cb57fda60099becd5ce3a224fc7fe62ba7409233a5dc5ab9556ce",
                "content_type": "application/json",
                "created_at": 1625688873000,
                "key": "config/settings_data.json",
                "public_url": "https://cdn-theme.myshopline.com/cdn/shop/prev/example/example/assets/component-blog.css"
              },
              "check_errors": [
                {
                  "filename": "assets/blog.css",
                  "message": [
                    "error content"
                  ],
                  "type": "FILE"
                }
              ]
            }
          },
          "examples": {
            "创建或修改主题文件": {
              "description": "创建或修改主题文件",
              "value": {
                "body": {
                  "asset": {
                    "created_at": 1743060738492,
                    "key": "sections/my-custom.html",
                    "public_url": null,
                    "size": 27,
                    "theme_id": "67d13fc3d92b88727dcd3755",
                    "updated_at": 1743060738492,
                    "checksum": "fc02382e0fd32e59f356299d45780299437b7f4188a788f04c8dbbac1a38680e",
                    "content_type": "text/html"
                  }
                }
              }
            }
          }
        }
      }
    },
    "401": {
      "headers": {
        "traceId": {
          "description": "请求的全局唯一标识符。用于追踪请求在系统中的流转，以便于问题发生时进行定位和调试。"
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "errors": {
                "description": "错误描述。",
                "type": "string"
              }
            },
            "required": [
              "errors"
            ]
          }
        }
      }
    },
    "429": {
      "headers": {
        "traceId": {
          "description": "请求的全局唯一标识符。用于追踪请求在系统中的流转，以便于问题发生时进行定位和调试。"
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "errors": {
                "description": "错误描述。",
                "type": "string"
              }
            },
            "required": [
              "errors"
            ]
          }
        }
      }
    }
  },
  "security": [
    {
      "oauth2": []
    }
  ],
  "method": "put",
  "path": "/themes/:theme_id/assets.json",
  "servers": [
    {
      "url": "https://{handle}.myshopline.com/admin/openapi",
      "variables": {
        "handle": {
          "default": "openapiceshidianpu",
          "description": "`handle` ：店铺的唯一标识符，值为店铺域名的前缀。例如，域名为 `open001.myshopline.com` 的店铺，其 `handle` 是 `open001` 。"
        }
      }
    }
  ],
  "info": {
    "title": "创建或修改主题文件",
    "version": "v20270301"
  },
  "authIndexes": [
    "write_themes"
  ]
}
```