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.

Issue when create ProductMedia

Issue when create ProductMedia

Bnk-shop
Shopify Partner
1 0 0

When i send a request using GraphQL to Create Product Media, it created an media record with no image (image return nil)
My x-request-id is: 894a6cae-a2b4-4202-96ca-c94d01f49d47

and my query is below: 

 

 

 

mutation {
        productCreateMedia(productId: "gid://shopify/Product/8116906590494", media: [ { alt: "", originalSource: "https://shopify-staged-uploads.storage.googleapis.com/tmp/69855510814/products/8f3e3f2c-ee85-44be-a226-dbdc6bcbeaf4/soba-noodles-sauce-garnishes-japanese-260nw-1100194787.jpg", mediaContentType: IMAGE } ]) {
          media {
            ... on MediaImage {
              id
              originalSource
              mediaContentType
            }
          }
          mediaUserErrors {
            code
            field
            message
          }
        }
      }

 

 

 

Reply 1 (1)

garyrgilbert
Shopify Partner
433 41 191

The image file you referenced does not exist. You got a null back because I believe you are incorrectly using the ... on MediaImage command.

 

But other than that if the file existed it should be created on the product.

 

Try this:

 

mutation {
        productCreateMedia(productId: "gid://shopify/Product/8116906590494", media: [ { alt: "", originalSource: "https://cdn.esawebb.org/archives/images/screen/weic2216b.jpg", mediaContentType: IMAGE } ]) {
          media {
            alt
            mediaContentType
            status
          }
          mediaUserErrors {
            code
            field
            message
          }
        }
      }

 

The response I got (with my own product id of course)

{
  "data": {
    "productCreateMedia": {
      "media": [
        {
          "alt": "",
          "mediaContentType": "IMAGE",
          "status": "UPLOADED"
        }
      ],
      "mediaUserErrors": []
    }
  },

 

Cheers,

 

Gary

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution