# fileDelete - admin-graphql - MUTATION Version: 2024-10 ## Description Deletes existing file assets that were uploaded to Shopify. ### Access Scopes `write_files` access scope. ## Arguments * [fileIds](/docs/api/admin-graphql/2024-10/scalars/ID): ID! - The IDs of the files to be deleted. ## Returns * [deletedFileIds](/docs/api/admin-graphql/2024-10/scalars/ID): ID The IDs of the deleted files. * [userErrors](/docs/api/admin-graphql/2024-10/objects/FilesUserError): FilesUserError! The list of errors that occurred from executing the mutation. ## Examples ### Delete a list of files 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 fileDelete($input: [ID!]!) { fileDelete(fileIds: $input) { deletedFileIds } }\",\n \"variables\": {\n \"input\": [\n \"gid://shopify/GenericFile/1072273199\",\n \"gid://shopify/MediaImage/1072273200\",\n \"gid://shopify/Video/1072273201\"\n ]\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation fileDelete($input: [ID!]!) {\n fileDelete(fileIds: $input) {\n deletedFileIds\n }\n }`,\n \"variables\": {\n \"input\": [\n \"gid://shopify/GenericFile/1072273199\",\n \"gid://shopify/MediaImage/1072273200\",\n \"gid://shopify/Video/1072273201\"\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 fileDelete($input: [ID!]!) {\n fileDelete(fileIds: $input) {\n deletedFileIds\n }\n }\nQUERY\n\nvariables = {\n \"input\": [\"gid://shopify/GenericFile/1072273199\", \"gid://shopify/MediaImage/1072273200\", \"gid://shopify/Video/1072273201\"]\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 fileDelete($input: [ID!]!) {\n fileDelete(fileIds: $input) {\n deletedFileIds\n }\n }`,\n {\n variables: {\n \"input\": [\n \"gid://shopify/GenericFile/1072273199\",\n \"gid://shopify/MediaImage/1072273200\",\n \"gid://shopify/Video/1072273201\"\n ]\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation fileDelete($input: [ID!]!) {\n fileDelete(fileIds: $input) {\n deletedFileIds\n }\n}" #### Graphql Input { "input": [ "gid://shopify/GenericFile/1072273199", "gid://shopify/MediaImage/1072273200", "gid://shopify/Video/1072273201" ] } #### Graphql Response { "data": { "fileDelete": { "deletedFileIds": [ "gid://shopify/GenericFile/1072273199", "gid://shopify/MediaImage/1072273200", "gid://shopify/Video/1072273201" ] } } } ### Deleting a file that doesn't exist returns an error 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 fileDelete($input: [ID!]!) { fileDelete(fileIds: $input) { deletedFileIds userErrors { message } } }\",\n \"variables\": {\n \"input\": [\n \"gid://shopify/GenericFile/1\"\n ]\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation fileDelete($input: [ID!]!) {\n fileDelete(fileIds: $input) {\n deletedFileIds\n userErrors {\n message\n }\n }\n }`,\n \"variables\": {\n \"input\": [\n \"gid://shopify/GenericFile/1\"\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 fileDelete($input: [ID!]!) {\n fileDelete(fileIds: $input) {\n deletedFileIds\n userErrors {\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": [\"gid://shopify/GenericFile/1\"]\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 fileDelete($input: [ID!]!) {\n fileDelete(fileIds: $input) {\n deletedFileIds\n userErrors {\n message\n }\n }\n }`,\n {\n variables: {\n \"input\": [\n \"gid://shopify/GenericFile/1\"\n ]\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation fileDelete($input: [ID!]!) {\n fileDelete(fileIds: $input) {\n deletedFileIds\n userErrors {\n message\n }\n }\n}" #### Graphql Input { "input": [ "gid://shopify/GenericFile/1" ] } #### Graphql Response { "data": { "fileDelete": { "deletedFileIds": null, "userErrors": [ { "message": "File id gid://shopify/GenericFile/1 does not exist." } ] } } }