File upload GraphQL api gives an error

Solved
HendryRaudsepp
Tourist
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 Solution (1)

Accepted Solutions
awwdam
Shopify Staff
Shopify Staff
241 40 30

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

Replies 3 (3)
awwdam
Shopify Staff
Shopify Staff
241 40 30

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
Tourist
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
New Member
1 0 2

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

 

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