File upload GraphQL api gives an error

Topic summary

A developer encountered an “access denied” error when attempting to use the fileCreate GraphQL mutation to upload files. The error message appeared garbled/reversed in the response.

Resolution:
The issue was resolved by adding the write_files access scope to the app’s permissions, as required by the Shopify Admin API documentation.

Follow-up questions:

  • Getting file IDs: After successful upload, file IDs can be retrieved by adding inline fragments to the query:

    ... on MediaImage { id }
    ... on GenericFile { id }
    
  • Related issue: Another user reported a “No such object” XML error when checking uploaded file URLs, suggesting potential problems with staged upload paths or file accessibility after creation.

Status: Original issue resolved; additional troubleshooting questions remain open regarding file ID retrieval and post-upload file access.

Summarized with AI on November 9. AI used: claude-sonnet-4-5-20250929.

QUERY

mutation fileCreate($files: [FileCreateInput!]!) {
  fileCreate(files: $files) {
    files {
      alt
      createdAt
    }
    userErrors {
      code
      field
      message
    }
  }
}

GRAPHQL VARIABLES

{
	"files": [
		{
            "alt": "Rainbow hearts on watercolor canvas",
	    	"originalSource": "https://cdn.shopify.com/s/files/1/0456/9399/2982/files/rainbow-wooden-hearts-lined-up-on-watercolour-canvas.jpg"
		}
	]
}

But I got this response. Am I missing something? Thanks in advance.

{
    "data": {
        "fileCreate": null
    },
    "errors": [
        {
            "message": "FileCreate access denied",
            "locations": [
                {
                    "line": 3,
                    "column": 3
                }
            ],
            "path": [
                "fileCreate"
            ]
        }
    ],
    "extensions": {
        "cost": {
            "requestedQueryCost": 10,
            "actualQueryCost": 10,
            "throttleStatus": {
                "maximumAvailable": 1000.0,
                "currentlyAvailable": 990,
                "restoreRate": 50.0
            }
        }
    }
}

Hey @HendryRaudsepp - just wanted to confirm if the app access has been updated to include the correct access scope - write_files - per our official API doc here? An app would need this scope access to successfully complete the mutation.

If you have updated your app include this and it’s still not working as expected, please share an x-request-id header returned from a request where this occurs. I would be happy to take a closer look and pass on any insights - Cheers!

1 Like

Hello, thanks for your answer. Now I can upload files using api. BTW - can you let me know how to get file ID ? When I try to update or delete file, api needs file ID. I have searched online for a long time, but I couldn’t find a way. Would be great if I can learn that. Cheers. Hendry

Add these lines to your fileCreate query to the files { } section:

...on MediaImage {
    id
}
...on GenericFile {
    id
}
2 Likes

@HendryRaudsepp , I am a fresher Shopify app. I have created an app for file upload using type script but get some errors when I am file uploading. so can you see and please tell me what I am missing? because the last few days I have been debugging but have not found any so please help me. I will share my code. I hope you check my please tell me. when I am resource URL check in the browser get an error XML related. “No such object: shopify-staged-uploads/tmp/86599663903/files/8436a409-6b08-4fb7-b706-6f5a76e64c47/Screenshot_from_2024-05-10_12-28-21.png”