Anchor to stagedUploadsCreatestaged
stagedUploadsCreate
mutation
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.
Anchor to Arguments
Arguments
- Anchor to inputinput•[Staged
Upload requiredInput!]! The information required to generate staged upload targets.
Was this section helpful?
Anchor to StagedUploadsCreatePayload returnsStagedUploadsCreatePayload returns
- Anchor to stagedTargetsstaged•
Targets The staged upload targets that were generated.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create staged upload targets
- stagedUploadsCreate reference
Examples
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",
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-04/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();
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"
}
]
},
},
});
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)
Input variables
JSON{
"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
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",