staged Uploads Createmutation
mutation
2024-01
Creates staged upload targets for each input. This is the first step in the upload process. The returned staged upload targets' URL and parameter fields can be used to send a request to upload the file described in the corresponding input.
For more information on the upload process, refer to Upload media to Shopify.
Arguments
The information required to generate staged upload targets.
Was this section helpful?
StagedUploadsCreatePayload returns
The staged upload targets that were generated.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Examples
Hide code
DescriptionCopy
mutation stagedUploadsCreate($input: [StagedUploadInput!]!) { stagedUploadsCreate(input: $input) { stagedTargets { url resourceUrl parameters { name value } } } }
curl -X POST \ https://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation stagedUploadsCreate($input: [StagedUploadInput!]!) { stagedUploadsCreate(input: $input) { stagedTargets { url resourceUrl parameters { name value } } } }", "variables": { "input": [ { "filename": "image1.png", "mimeType": "image/png", "httpMethod": "POST", "resource": "IMAGE" }, { "filename": "video.mp4", "mimeType": "video/mp4", "fileSize": "1234", "resource": "VIDEO" }, { "filename": "3d_model.glb", "mimeType": "model/gltf-binary", "resource": "MODEL_3D", "fileSize": "456" } ] } }'
const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation stagedUploadsCreate($input: [StagedUploadInput!]!) { stagedUploadsCreate(input: $input) { stagedTargets { url resourceUrl parameters { name value } } } }`, { variables: { "input": [ { "filename": "image1.png", "mimeType": "image/png", "httpMethod": "POST", "resource": "IMAGE" }, { "filename": "video.mp4", "mimeType": "video/mp4", "fileSize": "1234", "resource": "VIDEO" }, { "filename": "3d_model.glb", "mimeType": "model/gltf-binary", "resource": "MODEL_3D", "fileSize": "456" } ] }, }, ); const data = await response.json();
session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY mutation stagedUploadsCreate($input: [StagedUploadInput!]!) { stagedUploadsCreate(input: $input) { stagedTargets { url resourceUrl parameters { name value } } } } QUERY variables = { "input": [{"filename"=>"image1.png", "mimeType"=>"image/png", "httpMethod"=>"POST", "resource"=>"IMAGE"}, {"filename"=>"video.mp4", "mimeType"=>"video/mp4", "fileSize"=>"1234", "resource"=>"VIDEO"}, {"filename"=>"3d_model.glb", "mimeType"=>"model/gltf-binary", "resource"=>"MODEL_3D", "fileSize"=>"456"}] } response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation stagedUploadsCreate($input: [StagedUploadInput!]!) { stagedUploadsCreate(input: $input) { stagedTargets { url resourceUrl parameters { name value } } } }`, "variables": { "input": [ { "filename": "image1.png", "mimeType": "image/png", "httpMethod": "POST", "resource": "IMAGE" }, { "filename": "video.mp4", "mimeType": "video/mp4", "fileSize": "1234", "resource": "VIDEO" }, { "filename": "3d_model.glb", "mimeType": "model/gltf-binary", "resource": "MODEL_3D", "fileSize": "456" } ] }, }, });
use Shopify\Clients\Graphql; $client = new Graphql("your-development-store.myshopify.com", $accessToken); $query = <<<QUERY mutation stagedUploadsCreate($input: [StagedUploadInput!]!) { stagedUploadsCreate(input: $input) { stagedTargets { url resourceUrl parameters { name value } } } } QUERY; $variables = [ "input" => [{"filename"=>"image1.png", "mimeType"=>"image/png", "httpMethod"=>"POST", "resource"=>"IMAGE"}, {"filename"=>"video.mp4", "mimeType"=>"video/mp4", "fileSize"=>"1234", "resource"=>"VIDEO"}, {"filename"=>"3d_model.glb", "mimeType"=>"model/gltf-binary", "resource"=>"MODEL_3D", "fileSize"=>"456"}], ]; $response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{ "input": [ { "filename": "image1.png", "mimeType": "image/png", "httpMethod": "POST", "resource": "IMAGE" }, { "filename": "video.mp4", "mimeType": "video/mp4", "fileSize": "1234", "resource": "VIDEO" }, { "filename": "3d_model.glb", "mimeType": "model/gltf-binary", "resource": "MODEL_3D", "fileSize": "456" } ] }
Hide code
Response
JSON
{ "stagedUploadsCreate": { "stagedTargets": [ { "url": "https://snowdevil.myshopify.com/admin/tmp/files", "resourceUrl": "https://snowdevil.myshopify.com/tmp/26371970/products/a743377e-dca3-4d44-94a0-45ab3b06d592/image1.png", "parameters": [ { "name": "filename", "value": "image1.png" }, { "name": "mime_type", "value": "image/png" }, { "name": "key", "value": "tmp/26371970/products/a743377e-dca3-4d44-94a0-45ab3b06d592/image1.png" } ] }, { "url": "http://upload.example.com/target", "resourceUrl": "http://upload.example.com/target?external_video_id=25", "parameters": [ { "name": "GoogleAccessId", "value": "video-development@video-production123.iam.gserviceaccount.com" }, { "name": "key", "value": "dev/o/v/video.mp4" }, { "name": "policy", "value": "abc123" }, { "name": "signature", "value": "abc123" } ] }, { "url": "http://upload.example.com/target/dev/o/v/3d_model.glb?external_model3d_id=25", "resourceUrl": "http://upload.example.com/target/dev/o/v/3d_model.glb?external_model3d_id=25", "parameters": [ { "name": "GoogleAccessId", "value": "video-development@video-production123.iam.gserviceaccount.com" }, { "name": "key", "value": "dev/o/v/3d_model.glb" }, { "name": "policy", "value": "abc123" }, { "name": "signature", "value": "abc123" } ] } ] } }