---
title: "Create or update a theme file"
description: >
  Create or update a specified theme asset file. If the file does not exist, a new one is created using the provided information.
doc_type: openapi
doc_category: openapi
doc_version: v20270301
source_url:
  html: 'https://developer.shopline.com/docs/admin-rest-api/online-store/asset/create-or-update-a-theme-file'
  md: 'https://developer.shopline.com/docs/admin-rest-api/online-store/asset/create-or-update-a-theme-file.md'
---
# Create or update a theme file

Create or update a specified theme asset file. If the file does not exist, a new one is created using the provided information.

- **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` : The store's unique identifier, which is the prefix of the store's domain name. For example, if a store's domain name is `open001.myshopline.com` , the store handle is `open001` .

## Required Permissions

* `write_themes`

## Request

### Path Parameters

* `theme_id`

  string (required)

  The unique ID of the theme.

### Request Headers

* `Content-Type`

  string (required)

  The field must be set to the fixed value `application/json; charset=utf-8`.

* `Authorization`

  string (required)

   The access token for the API resource. Refer to [App authorization](https://developer.shopline.com/docs/apps/api-instructions-for-use/app-authorization.md?lang=en) to obtain the access token, and then pass the obtained token in the Bearer format. 

### Request Body

* `asset`

  object

  The theme asset file information to be created or modified. Specify one of the fields: `value`, `src`, `attachment`, or `source_key`. They cannot be used simultaneously or left all empty.

  * `source_key`

    string

    The name of the existing theme asset file to be copied. Specify one of the fields: `value`, `src`, `attachment`, or `source_key`. They cannot be used simultaneously or left all empty.

  * `src`

    string

    The download URL of the theme asset file. Specify one of the fields: `value`, `src`, `attachment`, or `source_key`. They cannot be used simultaneously or left all empty.

  * `value`

    string

    The textual content of the theme asset file. Specify one of the fields: `value`, `src`, `attachment`, or `source_key`. They cannot be used simultaneously or left all empty.

  * `attachment`

    string

    Image in Base64 encoding format. Format: [base64](https://en.wikipedia.org/wiki/Base64). Specify one of the fields: `value`, `src`, `attachment`, or `source_key`. They cannot be used simultaneously or left all empty.

  * `key`

    string

    The name of the theme asset file to be created or modified.

## Response

### Status Codes

* `200`

  For the complete list of codes and messages, see [Http status code](https://developer.shopline.com/docs/apps/api-instructions-for-use/http-status-code.md?lang=en).

* `401`

  

* `429`

  

### Response Headers

* `traceId`

  A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise.

### Response Body

#### 200

* `asset`

  object

  The information of the theme asset file.

  * `key`

    string

    The name of the theme asset file.

  * `public_url`

    string

    The public URL of the theme asset file.

  * `size`

    integer

    The size of the theme asset file. 
    Unit: bytes.

  * `theme_id`

    string

    The unique ID of the theme.

  * `updated_at`

    long

    The update time of the theme asset file, formatted as a 13-digit millisecond timestamp.

  * `checksum`

    string

    The MD5 checksum of the theme asset file. Format: [MD5](https://en.wikipedia.org/wiki/MD5).

  * `content_type`

    string

    The MIME type of the theme asset file, including a type and subtype indicating the file's format. Format: [MIME](https://en.wikipedia.org/wiki/Media_type).

  * `created_at`

    long

    The creation time of the theme asset file, formatted as a 13-digit millisecond timestamp.

* `check_errors`

  array<object>

  Validation error result.

  * `filename`

    string

    The name of the error file.

  * `message`

    array<string>

    Error message.

  * `type`

    string

    Error type.


#### 401

* `errors`

  string

  Error message. 


#### 429

* `errors`

  string

  Error message. 


## OpenAPI Definition

```json
{
  "tags": [
    "Create or update a theme file"
  ],
  "description": "Create or update a specified theme asset file. If the file does not exist, a new one is created using the provided information.",
  "externalDocs": {
    "description": "Permission point used by the interface is `write_themes` , For more information about the use of permission points, see",
    "url": "ec20/3cv5d7wpfgr6a8z5/xabczf5442284vkq?lang=en",
    "errorTableDescription": ""
  },
  "operationId": "nrtLU7Mw",
  "parameters": [
    {
      "name": "theme_id",
      "in": "path",
      "description": "The unique ID of the theme.",
      "required": true,
      "style": "simple",
      "schema": {
        "name": "theme_id",
        "description": "The unique ID of the theme.",
        "type": "string"
      },
      "examples": {
        "Create or update a theme file": {
          "value": "6388827102b701028efac460"
        }
      }
    },
    {
      "name": "Content-Type",
      "in": "header",
      "description": "The field must be set to the fixed value `application/json; charset=utf-8`.",
      "required": true,
      "schema": {
        "name": "Content-Type",
        "type": "string",
        "example": "application/json; charset=utf-8"
      }
    },
    {
      "name": "Authorization",
      "in": "header",
      "description": " The access token for the API resource. Refer to [App authorization](https://developer.shopline.com/docs/apps/api-instructions-for-use/app-authorization.md?lang=en) to obtain the access token, and then pass the obtained token in the Bearer format. ",
      "required": true,
      "style": "string",
      "schema": {
        "name": "Authorization",
        "description": " The access token for the API resource. Refer to [App authorization](https://developer.shopline.com/docs/apps/api-instructions-for-use/app-authorization.md?lang=en) to obtain the access token, and then pass the obtained token in the Bearer format. ",
        "type": "string",
        "example": "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MCwiYXBwS2V5IjoiNzU2ZjI1NWE2NjdlZTcwNTk1MzM0ZjVjYzk4NzU5MzBmN2E3NGZjMSIsImV4cCI6MTg3OTQ4MjA3NiwiaXNzIjoieXNvdWwiLCJzZWxsZXJJZCI6IjIwMDAyMzQ4ODAiLCJzdG9yZUlkIjoiMTY3MjM2OTcyOTYwNiIsInRpbWVzdGFtcCI6MTc4NDc4NzY3NjY2MSwidmVyc2lvbiI6IlYyIn0.3ZzbGAH4cLU1QR2VPEvMOQInUDvus-C4amkINSQIPuNVlXsFKj0sAt1c0KnUy9MWUOFV9cHlkf7J90r2y1FzpA"
      },
      "example": "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MCwiYXBwS2V5IjoiNzU2ZjI1NWE2NjdlZTcwNTk1MzM0ZjVjYzk4NzU5MzBmN2E3NGZjMSIsImV4cCI6MTg3OTQ4MjA3NiwiaXNzIjoieXNvdWwiLCJzZWxsZXJJZCI6IjIwMDAyMzQ4ODAiLCJzdG9yZUlkIjoiMTY3MjM2OTcyOTYwNiIsInRpbWVzdGFtcCI6MTc4NDc4NzY3NjY2MSwidmVyc2lvbiI6IlYyIn0.3ZzbGAH4cLU1QR2VPEvMOQInUDvus-C4amkINSQIPuNVlXsFKj0sAt1c0KnUy9MWUOFV9cHlkf7J90r2y1FzpA"
    }
  ],
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "name": "body",
          "description": "body position parameter",
          "type": "object",
          "properties": {
            "asset": {
              "name": "asset",
              "description": "The theme asset file information to be created or modified. Specify one of the fields: `value`, `src`, `attachment`, or `source_key`. They cannot be used simultaneously or left all empty.",
              "type": "object",
              "properties": {
                "source_key": {
                  "name": "source_key",
                  "description": "The name of the existing theme asset file to be copied. Specify one of the fields: `value`, `src`, `attachment`, or `source_key`. They cannot be used simultaneously or left all empty.",
                  "type": "string",
                  "example": "assets/original-image-store-close.png"
                },
                "src": {
                  "name": "src",
                  "description": "The download URL of the theme asset file. Specify one of the fields: `value`, `src`, `attachment`, or `source_key`. They cannot be used simultaneously or left all empty.",
                  "type": "string",
                  "example": "https://cdn-theme.myshopline.com/cdn/shop/prev/example/example/assets/component-blog.css"
                },
                "value": {
                  "name": "value",
                  "description": "The textual content of the theme asset file. Specify one of the fields: `value`, `src`, `attachment`, or `source_key`. They cannot be used simultaneously or left all empty.",
                  "type": "string",
                  "example": "<p>an example</p>"
                },
                "attachment": {
                  "name": "attachment",
                  "description": "Image in Base64 encoding format. Format: [base64](https://en.wikipedia.org/wiki/Base64). Specify one of the fields: `value`, `src`, `attachment`, or `source_key`. They cannot be used simultaneously or left all empty.",
                  "type": "string",
                  "example": "base64_content"
                },
                "key": {
                  "name": "key",
                  "description": "The name of the theme asset file to be created or modified.",
                  "type": "string",
                  "example": "assets/copied-image-store-close.png"
                }
              },
              "required": [
                "key"
              ],
              "example": {
                "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>",
                "attachment": "base64_content"
              }
            }
          },
          "required": [
            "asset"
          ],
          "example": {
            "asset": {
              "value": "<p>an example</p>",
              "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"
            }
          }
        },
        "examples": {
          "Create or update a theme file": {
            "description": "Create or update theme file",
            "value": {
              "body": {
                "asset": {
                  "key": "sections/my-custom.html",
                  "value": "<div> custom section </div>"
                }
              },
              "path": {
                "theme_id": "6388827102b701028efac460"
              }
            }
          }
        }
      }
    },
    "required": true
  },
  "responses": {
    "200": {
      "description": "For the complete list of codes and messages, see [Http status code](https://developer.shopline.com/docs/apps/api-instructions-for-use/http-status-code.md?lang=en).",
      "headers": {
        "traceId": {
          "description": "A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise."
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "name": "body",
            "type": "object",
            "properties": {
              "asset": {
                "name": "asset",
                "description": "The information of the theme asset file.",
                "type": "object",
                "properties": {
                  "key": {
                    "name": "key",
                    "description": "The name of the theme asset file.",
                    "type": "string",
                    "example": "config/settings_data.json"
                  },
                  "public_url": {
                    "name": "public_url",
                    "description": "The public URL of the theme asset file.",
                    "type": "string",
                    "example": "https://cdn-theme.myshopline.com/cdn/shop/prev/example/example/assets/component-blog.css"
                  },
                  "size": {
                    "name": "size",
                    "description": "The size of the theme asset file. \nUnit: bytes.",
                    "type": "integer",
                    "example": 204800
                  },
                  "theme_id": {
                    "name": "theme_id",
                    "description": "The unique ID of the theme.",
                    "type": "string",
                    "example": "671f4c96d2682a1f5407536e"
                  },
                  "updated_at": {
                    "name": "updated_at",
                    "description": "The update time of the theme asset file, formatted as a 13-digit millisecond timestamp.",
                    "type": "long",
                    "example": 1625688873000
                  },
                  "checksum": {
                    "name": "checksum",
                    "description": "The MD5 checksum of the theme asset file. Format: [MD5](https://en.wikipedia.org/wiki/MD5).",
                    "type": "string",
                    "example": "21cd91752e4cb57fda60099becd5ce3a224fc7fe62ba7409233a5dc5ab9556ce"
                  },
                  "content_type": {
                    "name": "content_type",
                    "description": "The MIME type of the theme asset file, including a type and subtype indicating the file's format. Format: [MIME](https://en.wikipedia.org/wiki/Media_type).",
                    "type": "string",
                    "example": "application/json"
                  },
                  "created_at": {
                    "name": "created_at",
                    "description": "The creation time of the theme asset file, formatted as a 13-digit millisecond timestamp.",
                    "type": "long",
                    "example": 1625688873000
                  }
                },
                "example": {
                  "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",
                  "updated_at": 1625688873000,
                  "checksum": "21cd91752e4cb57fda60099becd5ce3a224fc7fe62ba7409233a5dc5ab9556ce"
                }
              },
              "check_errors": {
                "name": "check_errors",
                "description": "Validation error result.",
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "filename": {
                      "name": "filename",
                      "description": "The name of the error file.",
                      "type": "string",
                      "example": "assets/blog.css"
                    },
                    "message": {
                      "name": "message",
                      "description": "Error message.",
                      "type": "array",
                      "items": {
                        "type": "string",
                        "example": "error content"
                      },
                      "example": [
                        "error content"
                      ]
                    },
                    "type": {
                      "name": "type",
                      "description": "Error type.",
                      "type": "string",
                      "example": "FILE"
                    }
                  },
                  "example": {
                    "filename": "assets/blog.css",
                    "message": [
                      "error content"
                    ],
                    "type": "FILE"
                  }
                },
                "example": [
                  {
                    "type": "FILE",
                    "filename": "assets/blog.css",
                    "message": [
                      "error content"
                    ]
                  }
                ]
              }
            },
            "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": {
            "Create or update a theme file": {
              "description": "Create or update theme file",
              "value": {
                "body": {
                  "asset": {
                    "key": "sections/my-custom.html",
                    "public_url": null,
                    "size": 27,
                    "theme_id": "67d13fc3d92b88727dcd3755",
                    "updated_at": 1743060738492,
                    "checksum": "fc02382e0fd32e59f356299d45780299437b7f4188a788f04c8dbbac1a38680e",
                    "content_type": "text/html",
                    "created_at": 1743060738492
                  }
                }
              }
            }
          }
        }
      }
    },
    "401": {
      "headers": {
        "traceId": {
          "description": "A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise."
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "errors": {
                "description": "Error message. ",
                "type": "string"
              }
            },
            "required": [
              "errors"
            ]
          }
        }
      }
    },
    "429": {
      "headers": {
        "traceId": {
          "description": "A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise."
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "errors": {
                "description": "Error message. ",
                "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` : The store's unique identifier, which is the prefix of the store's domain name. For example, if a store's domain name is `open001.myshopline.com` , the store handle is `open001` ."
        }
      }
    }
  ],
  "info": {
    "title": "Create or update a theme file",
    "version": "v20270301"
  },
  "authIndexes": [
    "write_themes"
  ]
}
```