# themeFilesUpsert - admin-graphql - MUTATION Version: 2024-10 ## Description Create or update theme files. ### Access Scopes 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](https://docs.google.com/forms/d/e/1FAIpQLSfZTB1vxFC5d1-GPdqYunWRGUoDcOheHQzfK2RoEFEHrknt5g/viewform). ## Arguments * [files](/docs/api/admin-graphql/2024-10/input-objects/OnlineStoreThemeFilesUpsertFileInput): OnlineStoreThemeFilesUpsertFileInput! - The files to update. * [themeId](/docs/api/admin-graphql/2024-10/scalars/ID): ID! - The theme to update. ## Returns * [job](/docs/api/admin-graphql/2024-10/objects/Job): Job The theme files write job triggered by the mutation. * [upsertedThemeFiles](/docs/api/admin-graphql/2024-10/objects/OnlineStoreThemeFileOperationResult): OnlineStoreThemeFileOperationResult The resulting theme files. * [userErrors](/docs/api/admin-graphql/2024-10/objects/OnlineStoreThemeFilesUserErrors): OnlineStoreThemeFilesUserErrors! The list of errors that occurred from executing the mutation. ## Examples ### Create or update a theme file Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) { themeFilesUpsert(files: $files, themeId: $themeId) { upsertedThemeFiles { filename } userErrors { field message } } }\",\n \"variables\": {\n \"themeId\": \"gid://shopify/OnlineStoreTheme/529529152\",\n \"files\": [\n {\n \"filename\": \"templates/index.json\",\n \"body\": {\n \"type\": \"TEXT\",\n \"value\": \"{ \\\"sections\\\": {}, \\\"order\\\": [] }\"\n }\n }\n ]\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {\n themeFilesUpsert(files: $files, themeId: $themeId) {\n upsertedThemeFiles {\n filename\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"themeId\": \"gid://shopify/OnlineStoreTheme/529529152\",\n \"files\": [\n {\n \"filename\": \"templates/index.json\",\n \"body\": {\n \"type\": \"TEXT\",\n \"value\": \"{ \\\"sections\\\": {}, \\\"order\\\": [] }\"\n }\n }\n ]\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {\n themeFilesUpsert(files: $files, themeId: $themeId) {\n upsertedThemeFiles {\n filename\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"themeId\": \"gid://shopify/OnlineStoreTheme/529529152\",\n \"files\": [{\"filename\"=>\"templates/index.json\", \"body\"=>{\"type\"=>\"TEXT\", \"value\"=>\"{ \\\"sections\\\": {}, \\\"order\\\": [] }\"}}]\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {\n themeFilesUpsert(files: $files, themeId: $themeId) {\n upsertedThemeFiles {\n filename\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"themeId\": \"gid://shopify/OnlineStoreTheme/529529152\",\n \"files\": [\n {\n \"filename\": \"templates/index.json\",\n \"body\": {\n \"type\": \"TEXT\",\n \"value\": \"{ \\\"sections\\\": {}, \\\"order\\\": [] }\"\n }\n }\n ]\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {\n themeFilesUpsert(files: $files, themeId: $themeId) {\n upsertedThemeFiles {\n filename\n }\n userErrors {\n field\n message\n }\n }\n}" #### Graphql Input { "themeId": "gid://shopify/OnlineStoreTheme/529529152", "files": [ { "filename": "templates/index.json", "body": { "type": "TEXT", "value": "{ \"sections\": {}, \"order\": [] }" } } ] } #### Graphql Response { "data": { "themeFilesUpsert": { "upsertedThemeFiles": [ { "filename": "templates/index.json" } ], "userErrors": [] } } } ### Create or update theme files in bulk Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) { themeFilesUpsert(files: $files, themeId: $themeId) { upsertedThemeFiles { filename } job { id } userErrors { field message } } }\",\n \"variables\": {\n \"themeId\": \"gid://shopify/OnlineStoreTheme/529529152\",\n \"files\": [\n {\n \"filename\": \"templates/index.json\",\n \"body\": {\n \"type\": \"TEXT\",\n \"value\": \"{ \\\"sections\\\": {}, \\\"order\\\": [] }\"\n }\n },\n {\n \"filename\": \"assets/custom-content.txt\",\n \"body\": {\n \"type\": \"BASE64\",\n \"value\": \"Y3VzdG9tIGNvbnRlbnQ=\"\n }\n },\n {\n \"filename\": \"assets/large-dog-image.jpg\",\n \"body\": {\n \"type\": \"URL\",\n \"value\": \"https://www.example.com/large-dog-image.jpg\"\n }\n }\n ]\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {\n themeFilesUpsert(files: $files, themeId: $themeId) {\n upsertedThemeFiles {\n filename\n }\n job {\n id\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"themeId\": \"gid://shopify/OnlineStoreTheme/529529152\",\n \"files\": [\n {\n \"filename\": \"templates/index.json\",\n \"body\": {\n \"type\": \"TEXT\",\n \"value\": \"{ \\\"sections\\\": {}, \\\"order\\\": [] }\"\n }\n },\n {\n \"filename\": \"assets/custom-content.txt\",\n \"body\": {\n \"type\": \"BASE64\",\n \"value\": \"Y3VzdG9tIGNvbnRlbnQ=\"\n }\n },\n {\n \"filename\": \"assets/large-dog-image.jpg\",\n \"body\": {\n \"type\": \"URL\",\n \"value\": \"https://www.example.com/large-dog-image.jpg\"\n }\n }\n ]\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {\n themeFilesUpsert(files: $files, themeId: $themeId) {\n upsertedThemeFiles {\n filename\n }\n job {\n id\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"themeId\": \"gid://shopify/OnlineStoreTheme/529529152\",\n \"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\"}}]\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {\n themeFilesUpsert(files: $files, themeId: $themeId) {\n upsertedThemeFiles {\n filename\n }\n job {\n id\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"themeId\": \"gid://shopify/OnlineStoreTheme/529529152\",\n \"files\": [\n {\n \"filename\": \"templates/index.json\",\n \"body\": {\n \"type\": \"TEXT\",\n \"value\": \"{ \\\"sections\\\": {}, \\\"order\\\": [] }\"\n }\n },\n {\n \"filename\": \"assets/custom-content.txt\",\n \"body\": {\n \"type\": \"BASE64\",\n \"value\": \"Y3VzdG9tIGNvbnRlbnQ=\"\n }\n },\n {\n \"filename\": \"assets/large-dog-image.jpg\",\n \"body\": {\n \"type\": \"URL\",\n \"value\": \"https://www.example.com/large-dog-image.jpg\"\n }\n }\n ]\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {\n themeFilesUpsert(files: $files, themeId: $themeId) {\n upsertedThemeFiles {\n filename\n }\n job {\n id\n }\n userErrors {\n field\n message\n }\n }\n}" #### Graphql Input { "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" } } ] } #### Graphql Response { "data": { "themeFilesUpsert": { "upsertedThemeFiles": [ { "filename": "templates/index.json" }, { "filename": "assets/custom-content.txt" } ], "job": { "id": "gid://shopify/Job/ae8d210d-90e0-4912-96d0-96d45c5e8fbb" }, "userErrors": [] } } }