Upsert Theme File

POST /v2/sites/{site_id}/themes/{theme_id}/files

Creates or updates a theme file for a Square Online site. This operation creates a file in the theme directory of the site. If the file already exists at the specified path, Square replaces the file.

The following MIME types are supported:

  • application/octet-stream
  • text/plain
  • text/css
  • text/javascript
  • text/json
  • text/html
  • text/markdown
  • image/jpeg
  • image/bmp
  • image/gif
  • image/png
  • image/svg+xml
  • image/webp
  • font/woff
  • font/woff2

application/json is not a supported MIME type because it’s reserved for the multipart/form-data part of the request. To upload a JSON file, you can use application/octet-stream or text/json to override the content type (for example, file=@myFile.json;type=text/json for cURL).

Permissions: ONLINE_STORE_CUSTOM_THEME_WRITE

Path parameters

Name Type Description
site_id string Required The ID of the site.
theme_id string Required The ID of the theme.

Request body

Name Type Description
path string Required The path and filename of the theme file to create or update.

Response fields

Name Type Description
errors Error [ ] Any errors that occurred during the request.
file ThemeFile The new or updated theme file.

Example request

curl /v2/sites/site_id0/themes/theme_id1/files \
  -X POST \
  -H 'Square-Version: 2023-09-25' \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H "Content-Type: multipart/related; boundary=BOUNDARY" \
  --data-binary \
    '
    --BOUNDARY
    Content-Type: application/json; charset=UTF-8

    {
      "path": "theme/partials/file_name2.twig"
    }

    --BOUNDARY
    Content-Type: text/plain

    <h1>Hello world</h1>
    --BOUNDARY--
  '

Example response

{
  "file": {
    "path": "theme/partials/header.twig",
    "content": "<h1>Hello world</h1>",
    "checksum": "7e85c676fd97d370e2309003a5681bc4388306979b7db04c37c6fb0672891b6a",
    "content_type": "text/plain",
    "size": 1542,
    "site_theme_id": "site_theme_413f6836-4c8d-4fee-8cb1-6d8bd042c880",
    "updated_at": "2020-11-23T02:19:10.000000Z"
  }
}