Create or update a theme file
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\": [] }"
}
}
]
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-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\": [] }"
}
}
]
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
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 json = await response.json();
return json.data;
}
Ruby
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)
Node.js
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\": [] }"
}
}
]
},
},
});
Shopify CLI
shopify app execute \
--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\": [] }"
}
}
]
}'
Direct API Access
const response = await fetch('shopify:admin/api/2026-04/graphql.json', {
method: 'POST',
body: JSON.stringify({
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 { data } = await response.json();
console.log(data);
Response
{
"themeFilesUpsert": {
"upsertedThemeFiles": [
{
"filename": "templates/index.json"
}
],
"userErrors": []
}
}
Create or update theme files in bulk
Query
mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {
themeFilesUpsert(files: $files, themeId: $themeId) {
upsertedThemeFiles {
filename
}
job {
id
}
userErrors {
field
message
}
}
}
Variables
{
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [
{
"filename": "templates/index.json",
"body": {
"type": "TEXT",
"value": "{ \"sections\": {}, \"order\": [] }"
}
},
{
"filename": "assets/custom-content.txt",
"body": {
"type": "BASE64",
"value": "Y3VzdG9tIGNvbnRlbnQ="
}
},
{
"filename": "assets/large-dog-image.jpg",
"body": {
"type": "URL",
"value": "https://www.example.com/large-dog-image.jpg"
}
}
]
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-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 } job { id } userErrors { field message } } }",
"variables": {
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [
{
"filename": "templates/index.json",
"body": {
"type": "TEXT",
"value": "{ \"sections\": {}, \"order\": [] }"
}
},
{
"filename": "assets/custom-content.txt",
"body": {
"type": "BASE64",
"value": "Y3VzdG9tIGNvbnRlbnQ="
}
},
{
"filename": "assets/large-dog-image.jpg",
"body": {
"type": "URL",
"value": "https://www.example.com/large-dog-image.jpg"
}
}
]
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
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
}
job {
id
}
userErrors {
field
message
}
}
}`,
{
variables: {
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [
{
"filename": "templates/index.json",
"body": {
"type": "TEXT",
"value": "{ \"sections\": {}, \"order\": [] }"
}
},
{
"filename": "assets/custom-content.txt",
"body": {
"type": "BASE64",
"value": "Y3VzdG9tIGNvbnRlbnQ="
}
},
{
"filename": "assets/large-dog-image.jpg",
"body": {
"type": "URL",
"value": "https://www.example.com/large-dog-image.jpg"
}
}
]
},
},
);
const json = await response.json();
return json.data;
}
Ruby
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
}
job {
id
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [
{
"filename": "templates/index.json",
"body": {
"type": "TEXT",
"value": "{ \"sections\": {}, \"order\": [] }"
}
},
{
"filename": "assets/custom-content.txt",
"body": {
"type": "BASE64",
"value": "Y3VzdG9tIGNvbnRlbnQ="
}
},
{
"filename": "assets/large-dog-image.jpg",
"body": {
"type": "URL",
"value": "https://www.example.com/large-dog-image.jpg"
}
}
]
}
response = client.query(query: query, variables: variables)
Node.js
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
}
job {
id
}
userErrors {
field
message
}
}
}`,
"variables": {
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [
{
"filename": "templates/index.json",
"body": {
"type": "TEXT",
"value": "{ \"sections\": {}, \"order\": [] }"
}
},
{
"filename": "assets/custom-content.txt",
"body": {
"type": "BASE64",
"value": "Y3VzdG9tIGNvbnRlbnQ="
}
},
{
"filename": "assets/large-dog-image.jpg",
"body": {
"type": "URL",
"value": "https://www.example.com/large-dog-image.jpg"
}
}
]
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {
themeFilesUpsert(files: $files, themeId: $themeId) {
upsertedThemeFiles {
filename
}
job {
id
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [
{
"filename": "templates/index.json",
"body": {
"type": "TEXT",
"value": "{ \"sections\": {}, \"order\": [] }"
}
},
{
"filename": "assets/custom-content.txt",
"body": {
"type": "BASE64",
"value": "Y3VzdG9tIGNvbnRlbnQ="
}
},
{
"filename": "assets/large-dog-image.jpg",
"body": {
"type": "URL",
"value": "https://www.example.com/large-dog-image.jpg"
}
}
]
}'
Direct API Access
const response = await fetch('shopify:admin/api/2026-04/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {
themeFilesUpsert(files: $files, themeId: $themeId) {
upsertedThemeFiles {
filename
}
job {
id
}
userErrors {
field
message
}
}
}
`,
variables: {
"themeId": "gid://shopify/OnlineStoreTheme/529529152",
"files": [
{
"filename": "templates/index.json",
"body": {
"type": "TEXT",
"value": "{ \"sections\": {}, \"order\": [] }"
}
},
{
"filename": "assets/custom-content.txt",
"body": {
"type": "BASE64",
"value": "Y3VzdG9tIGNvbnRlbnQ="
}
},
{
"filename": "assets/large-dog-image.jpg",
"body": {
"type": "URL",
"value": "https://www.example.com/large-dog-image.jpg"
}
}
]
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"themeFilesUpsert": {
"upsertedThemeFiles": [
{
"filename": "templates/index.json"
},
{
"filename": "assets/custom-content.txt"
}
],
"job": {
"id": "gid://shopify/Job/ae8d210d-90e0-4912-96d0-96d45c5e8fbb"
},
"userErrors": []
}
}