What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: File upload GraphQL api gives an error

Solved

File upload GraphQL api gives an error

HendryRaudsepp
Shopify Partner
4 0 0

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
            }
        }
    }
}

 

 

 

HendryRaudsepp_0-1630917989150.png

 

Accepted Solutions (2)

awwdam
Shopify Staff
249 42 38

This is an accepted solution.

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!

awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

JanGuardian
Visitor
1 1 2

This is an accepted solution.

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

 

...on MediaImage {
    id
}
...on GenericFile {
    id
}

 

 

View solution in original post

Replies 4 (4)

awwdam
Shopify Staff
249 42 38

This is an accepted solution.

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!

awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

HendryRaudsepp
Shopify Partner
4 0 0

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

JanGuardian
Visitor
1 1 2

This is an accepted solution.

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

 

...on MediaImage {
    id
}
...on GenericFile {
    id
}

 

 

mohitpatel
Shopify Partner
15 0 0

@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"