Anchor to themeFilesUpserttheme
themeFilesUpsert
mutation
Requires The user needs write_themes and an exemption from Shopify to modify theme files. If you think that your app is eligible for an exemption and should have access to this API, then you can submit an exception request.
Create or update theme files.
Anchor to Arguments
Arguments
- Anchor to filesfiles•
The files to update.
- Anchor to themeIdtheme•
Id ID!required The theme to update.
Was this section helpful?
Anchor to ThemeFilesUpsertPayload returnsThemeFilesUpsertPayload returns
- •
The theme files write job triggered by the mutation.
- Anchor to upsertedThemeFilesupserted•
Theme Files The resulting theme files.
- Anchor to userErrorsuser•
Errors The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create or update a theme file
- Create or update theme files in bulk
- themeFilesUpsert reference
Examples
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {
themeFilesUpsert(files: $files, themeId: $themeId) {
upsertedThemeFiles {
filename
}
userErrors {
field
message
}
}
}`,
{
variables: {
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [
{
"filename": "templates/index.json",
"body": {
"type": "TEXT",
"value": "{ \"sections\": {}, \"order\": [] }"
mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {
themeFilesUpsert(files: $files, themeId: $themeId) {
upsertedThemeFiles {
filename
}
userErrors {
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) { themeFilesUpsert(files: $files, themeId: $themeId) { upsertedThemeFiles { filename } userErrors { field message } } }",
"variables": {
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [
{
"filename": "templates/index.json",
"body": {
"type": "TEXT",
"value": "{ \"sections\": {}, \"order\": [] }"
}
}
]
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {
themeFilesUpsert(files: $files, themeId: $themeId) {
upsertedThemeFiles {
filename
}
userErrors {
field
message
}
}
}`,
{
variables: {
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [
{
"filename": "templates/index.json",
"body": {
"type": "TEXT",
"value": "{ \"sections\": {}, \"order\": [] }"
}
}
]
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {
themeFilesUpsert(files: $files, themeId: $themeId) {
upsertedThemeFiles {
filename
}
userErrors {
field
message
}
}
}`,
"variables": {
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [
{
"filename": "templates/index.json",
"body": {
"type": "TEXT",
"value": "{ \"sections\": {}, \"order\": [] }"
}
}
]
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {
themeFilesUpsert(files: $files, themeId: $themeId) {
upsertedThemeFiles {
filename
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [{"filename"=>"templates/index.json", "body"=>{"type"=>"TEXT", "value"=>"{ \"sections\": {}, \"order\": [] }"}}]
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [
{
"filename": "templates/index.json",
"body": {
"type": "TEXT",
"value": "{ \"sections\": {}, \"order\": [] }"
}
}
]
}
Response
JSON{
"themeFilesUpsert": {
"upsertedThemeFiles": [
{
"filename": "templates/index.json"
}
],
"userErrors": []
}
}