how to import media via graphql admin API

Highlighted
Shopify Partner
18 0 1

I have found a tutorial article 

 

https://shopify.dev/tutorials/manage-product-media-with-admin-api

 

but seems it's out of date.

 

I tried a couple of times, now I m be able to generate upload URLs.   But I don't what to do next anymore..

 

 

{
        stagedUploadTargetsGenerate: {
          urls: [
            {
              url:
                'https://shopify.s3.amazonaws.com/tmp/35427221636/products/c8d5a75b-eda4-4750-81fb-52ad458b8ab0/530a580e2fa76705161194c5957df3062c6214af.png?x-amz-acl=private&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJYM555KVYEWGJDKQ%2F20200427%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200427T031701Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=a6419de57732109233d3c3d102226185537cab8868f25bb446a3c3da3c110135',
              parameters: [
                { name: 'content_type', value: 'image/png' },
                { name: 'acl', value: 'private' },
                {
                  name: 'resource_url',
                  value:
                    'https://shopify.s3.amazonaws.com/tmp/35427221636/products/c8d5a75b-eda4-4750-81fb-52ad458b8ab0/530a580e2fa76705161194c5957df3062c6214af.png'
                }
              ]
            }
          ],
          userErrors: []
        }
      }

I have tried send via post request , but don't work.

0 Likes
Highlighted
Highlighted
Shopify Partner
18 0 1

 

I did like you said, they return me a "1",  no URL return.. 

0 Likes
Highlighted
Shopify Partner
18 0 1

1588132706052.jpg

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1040 139 164

I don't think that step should return a response body - now try handing that URL to the productAppendImages mutation.

0 Likes
Highlighted
Shopify Partner
18 0 1

yea I can.. but since nothing response,  How can I do that mutation?  

https://shopify-dev.shopifycloud.com/docs/admin-api/graphql/reference/mutation/input-object/producta...

this mutation needs an image input.

where can I get the image ID?

 

 

 

    

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1040 139 164

The variables would look something like this:

 

{
  "input": {
    "id": "gid://shopify/Product/<product id>",
    "images": [
      { "altText": "hello", "src": "<the same url used in your PUT request>" }
    ]
  }
}

 

0 Likes
Highlighted
Shopify Partner
18 0 1

woo, that finally works! thanks.  

one side question.  Can I use this image another way? such as insert in a blog article. 

or I can only use it for the product?

 

 

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1040 139 164

Awesome! Unfortunately not, only via the API.

0 Likes