file Createmutation
Requires write
access scope, write
access scope or write
access scope.
Creates file assets using an external URL or for files that were previously uploaded using the stagedUploadsCreate mutation. These files are added to the Files page in Shopify admin.
Files are processed asynchronously. Some data is not available until processing is completed. Check fileStatus to know when the files are READY or FAILED. See the FileStatus for the complete set of possible fileStatus values.
To get a list of all files, use the files query.
Arguments
List of new files to be created.
FileCreatePayload returns
The newly created files.
The list of errors that occurred from executing the mutation.
Code examples for MUTATION: fileCreate
Query Reference for MUTATION: fileCreate
"mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n # File fields\n }\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: fileCreate
"{\n \"files\": [\n {\n \"alt\": \"<your-alt>\",\n \"contentType\": \"EXTERNAL_VIDEO\",\n \"duplicateResolutionMode\": \"APPEND_UUID\",\n \"filename\": \"<your-filename>\",\n \"originalSource\": \"<your-originalSource>\"\n }\n ]\n}"
Schema Reference for MUTATION: fileCreate
"input FileCreateInput {\n alt: String\n contentType: FileContentType\n duplicateResolutionMode: FileCreateInputDuplicateResolutionMode\n filename: String\n originalSource: String!\n}\n"
Display Examples for MUTATION: fileCreate
[ { "example": { "type_name": "filecreate", "title": "Create a file using a staged upload URL", "description": "Create a file asset using a staged upload URL. Assumes a file has already been uploaded to the staged upload target", "query_string": "mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n}", "variables": { "files": { "alt": "fallback text for a video", "contentType": "VIDEO", "originalSource": "https://snowdevil.myshopify.com/admin/tmp/files" } }, "response": { "data": { "fileCreate": { "files": [] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/merchandising/test/unit/graph_api/admin/mutations/file_create_test.rb", "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 fileCreate($files: [FileCreateInput!]!) { fileCreate(files: $files) { files { id fileStatus alt createdAt } } }\",\n \"variables\": {\n \"files\": {\n \"alt\": \"fallback text for a video\",\n \"contentType\": \"VIDEO\",\n \"originalSource\": \"https://snowdevil.myshopify.com/admin/tmp/files\"\n }\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n }`,\n {\n variables: {\n \"files\": {\n \"alt\": \"fallback text for a video\",\n \"contentType\": \"VIDEO\",\n \"originalSource\": \"https://snowdevil.myshopify.com/admin/tmp/files\"\n }\n },\n },\n);\n\nconst data = await response.json();\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 fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n }\nQUERY\n\nvariables = {\n \"files\": {\n \"alt\": \"fallback text for a video\",\n \"contentType\": \"VIDEO\",\n \"originalSource\": \"https://snowdevil.myshopify.com/admin/tmp/files\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n }`,\n \"variables\": {\n \"files\": {\n \"alt\": \"fallback text for a video\",\n \"contentType\": \"VIDEO\",\n \"originalSource\": \"https://snowdevil.myshopify.com/admin/tmp/files\"\n }\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n }\nQUERY;\n\n$variables = [\n \"files\" => [\n \"alt\" => \"fallback text for a video\",\n \"contentType\" => \"VIDEO\",\n \"originalSource\" => \"https://snowdevil.myshopify.com/admin/tmp/files\",\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "files", "description": "List of new files to be created.", "type": { "kind": "INPUT_OBJECT", "name": "FileCreateInput", "list": true, "non_null": true }, "defaultValue": null, "typeSignature": "[FileCreateInput!]!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "files", "argValue": " {\"alt\":\"fallback text for a video\",\"contentType\":\"VIDEO\",\"originalSource\":\"https://snowdevil.myshopify.com/admin/tmp/files\"}", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "filecreate", "title": "Create a file using an external URL", "description": "Create an image file using an external URL as the source", "query_string": "mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n}", "variables": { "files": { "alt": "fallback text for an image", "contentType": "IMAGE", "originalSource": "https://example.com/image.jpg" } }, "response": { "data": { "fileCreate": { "files": [ { "id": "gid://shopify/MediaImage/1072273195", "fileStatus": "UPLOADED", "alt": "fallback text for an image", "createdAt": "2024-09-12T01:07:45Z" } ] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/merchandising/test/unit/graph_api/admin/mutations/file_create_test.rb", "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 fileCreate($files: [FileCreateInput!]!) { fileCreate(files: $files) { files { id fileStatus alt createdAt } } }\",\n \"variables\": {\n \"files\": {\n \"alt\": \"fallback text for an image\",\n \"contentType\": \"IMAGE\",\n \"originalSource\": \"https://example.com/image.jpg\"\n }\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n }`,\n {\n variables: {\n \"files\": {\n \"alt\": \"fallback text for an image\",\n \"contentType\": \"IMAGE\",\n \"originalSource\": \"https://example.com/image.jpg\"\n }\n },\n },\n);\n\nconst data = await response.json();\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 fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n }\nQUERY\n\nvariables = {\n \"files\": {\n \"alt\": \"fallback text for an image\",\n \"contentType\": \"IMAGE\",\n \"originalSource\": \"https://example.com/image.jpg\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n }`,\n \"variables\": {\n \"files\": {\n \"alt\": \"fallback text for an image\",\n \"contentType\": \"IMAGE\",\n \"originalSource\": \"https://example.com/image.jpg\"\n }\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n }\nQUERY;\n\n$variables = [\n \"files\" => [\n \"alt\" => \"fallback text for an image\",\n \"contentType\" => \"IMAGE\",\n \"originalSource\" => \"https://example.com/image.jpg\",\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "files", "description": "List of new files to be created.", "type": { "kind": "INPUT_OBJECT", "name": "FileCreateInput", "list": true, "non_null": true }, "defaultValue": null, "typeSignature": "[FileCreateInput!]!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "files", "argValue": " {\"alt\":\"fallback text for an image\",\"contentType\":\"IMAGE\",\"originalSource\":\"https://example.com/image.jpg\"}", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "filecreate", "title": "Create an image with custom filename", "description": "Specify a custom filename to be used when creating image", "query_string": "mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n}", "variables": { "files": { "alt": "fallback text for an image", "contentType": "IMAGE", "originalSource": "https://burst.shopifycdn.com/photos/pug-in-city.jpg", "filename": "dog.jpg" } }, "response": { "data": { "fileCreate": { "files": [ { "id": "gid://shopify/MediaImage/1072273196", "fileStatus": "UPLOADED", "alt": "fallback text for an image", "createdAt": "2024-09-12T01:07:45Z" } ] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/merchandising/test/unit/graph_api/admin/mutations/file_create_test.rb", "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 fileCreate($files: [FileCreateInput!]!) { fileCreate(files: $files) { files { id fileStatus alt createdAt } } }\",\n \"variables\": {\n \"files\": {\n \"alt\": \"fallback text for an image\",\n \"contentType\": \"IMAGE\",\n \"originalSource\": \"https://burst.shopifycdn.com/photos/pug-in-city.jpg\",\n \"filename\": \"dog.jpg\"\n }\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n }`,\n {\n variables: {\n \"files\": {\n \"alt\": \"fallback text for an image\",\n \"contentType\": \"IMAGE\",\n \"originalSource\": \"https://burst.shopifycdn.com/photos/pug-in-city.jpg\",\n \"filename\": \"dog.jpg\"\n }\n },\n },\n);\n\nconst data = await response.json();\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 fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n }\nQUERY\n\nvariables = {\n \"files\": {\n \"alt\": \"fallback text for an image\",\n \"contentType\": \"IMAGE\",\n \"originalSource\": \"https://burst.shopifycdn.com/photos/pug-in-city.jpg\",\n \"filename\": \"dog.jpg\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n }`,\n \"variables\": {\n \"files\": {\n \"alt\": \"fallback text for an image\",\n \"contentType\": \"IMAGE\",\n \"originalSource\": \"https://burst.shopifycdn.com/photos/pug-in-city.jpg\",\n \"filename\": \"dog.jpg\"\n }\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation fileCreate($files: [FileCreateInput!]!) {\n fileCreate(files: $files) {\n files {\n id\n fileStatus\n alt\n createdAt\n }\n }\n }\nQUERY;\n\n$variables = [\n \"files\" => [\n \"alt\" => \"fallback text for an image\",\n \"contentType\" => \"IMAGE\",\n \"originalSource\" => \"https://burst.shopifycdn.com/photos/pug-in-city.jpg\",\n \"filename\" => \"dog.jpg\",\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "files", "description": "List of new files to be created.", "type": { "kind": "INPUT_OBJECT", "name": "FileCreateInput", "list": true, "non_null": true }, "defaultValue": null, "typeSignature": "[FileCreateInput!]!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "files", "argValue": " {\"alt\":\"fallback text for an image\",\"contentType\":\"IMAGE\",\"originalSource\":\"https://burst.shopifycdn.com/photos/pug-in-city.jpg\",\"filename\":\"dog.jpg\"}", "typeKind": "MUTATION" } ] } ]