Deleting images ... which id to use?

Given this node

{
        "node": {
            "id": "gid://shopify/MediaImage/32425425993806",
            "alt": "FIBREGLASS SINGLE SIDED STEP LADDER - Close Up",
            "createdAt": "2025-12-09T04:49:31Z",
            "updatedAt": "2025-12-09T04:49:34Z",
            "fileStatus": "READY",
            "status": "READY",
            "mediaContentType": "IMAGE",
            "fileErrors": [
            ],
            "mediaErrors": [
            ],
            "mediaWarnings": [
            ],
            "image": {
                "url": "https://cdn.shopify.com/s/files/1/0702/5816/3790/files/FIBREGLASS-SINGLE-SIDED-STEP-LADDER-Close-Up-min_f15d16e3-7c19-4c25-96c0-aa4751dfdaca.png?v=1765255774",
                "width": 2000,
                "height": 2000,
                "altText": "FIBREGLASS SINGLE SIDED STEP LADDER - Close Up",
                "id": "gid://shopify/ImageSource/32457454059598"
            },
            "originalSource": {
                "fileSize": 694285,
                "url": "https://shopify-shop-assets.storage.googleapis.com/s/files/1/d/96e7/0702/5816/3790/files/FIBREGLASS-SINGLE-SIDED-STEP-LADDER-Close-Up-min_f15d16e3-7c19-4c25-96c0-aa4751dfdaca.png?REDACTED"
            },
            "preview": {
                "status": "READY",
                "image": {
                    "url": "https://cdn.shopify.com/s/files/1/0702/5816/3790/files/FIBREGLASS-SINGLE-SIDED-STEP-LADDER-Close-Up-min_f15d16e3-7c19-4c25-96c0-aa4751dfdaca.png?v=1765255774",
                    "width": 2000,
                    "height": 2000
                }
            },
            "translations": [
            ]
        },
        "cursor": "eyJsYXN0X2lkIjozMjQyNTQyNTk5MzgwNiwibGFzdF92YWx1ZSI6IjMyNDI1NDI1OTkzODA2In0="
    }

which id should used when deleting the image? There’s the node.id and node.image.id.

The context for this is in writing code to minimise the number of duplicated images. I tried usingduplicateResolutionMode's RAISE_ERRORbut didn’t get any feedback in the initial upload. An AI says that I should expect to see data in the userErrors but I’m not seeing anything there except an empty array. I was rather hoping to be able to attempt to upload, get a response that indicates the file is already present and the gid of the the original and be able to use that as the gid in my google sheet.

Hi @Bruce_Axtens

To delete this image (or any media image), you should always use node.id (gid://shopify/MediaImage/...), not node.image.id. The node.id is the ID of the MediaImage file object as understood by the Files API and by mutations like fileDelete and productDeleteMedia. The node.image.id is the underlying ImageSource ID, which is not what deletion mutations expect.

The duplicateResolutionMode: RAISE_ERROR flag on fileCreate controls what happens when the filename is already in use: Shopify can append a UUID, replace the existing file, or raise an error. When it raises an error, you’ll see it in the userErrors array as a FilesUserError with field, message, and a code from FilesErrorCode. However, even when duplication is detected, the error payload does not include the ID of the existing file, so you don’t get the “original MediaImage GID” from that mutation alone.

Because of that limitation, the usual way to minimize duplicates and keep a usable ID for your Google Sheet is: (1) maintain your own mapping from some canonical key (e.g. original URL or content hash) to the returned MediaImage id and consult that before uploading; and optionally (2) use the files query to search existing images (for reconciliation or recovery) based on filters like media_type:IMAGE and then match on URL/filename. With this approach, you can both avoid redundant uploads and reliably use the correct gid://shopify/MediaImage/... for deletes and references.