Issue with Using MediaSrc in productUpdate Mutation

Issue with Using MediaSrc in productUpdate Mutation

captainpryce
Shopify Partner
2 0 1

Hello,

I am experiencing an issue passing the mediaSrc variable into my productUpdate mutation. According to the documentation, it states that the mediaSrc key can only be passed to mutations "that create media images and must match one of the URLs being created on the product". My understanding of this is that I would need to create a product media image with a URL that matches the one that is being passed into the "mediaSrc" variable.

Unfortunately, when doing this, the media is uploaded fine but the image is not being attached to the specific product variant.

Here is the mutation I am running:

 

mutation UpdateProductWithNewMedia($input: ProductInput!, $media: [CreateMediaInput!]) {
  productUpdate(input: $input, media: $media) {
    product {
      id
      media(first: 10) {
        nodes {
          alt
          mediaContentType
          preview {
            status
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

 

 

And here are the variables that are being passed:

{
  "input": {
    "id": "gid://shopify/Product/8971462902048",
    "variants": [
      {
        "options": ["New Variant Value 1", "New Variant Value 2", "New Variant Value 3"],
        "mediaSrc": ["https://kinsta.com/wp-content/uploads/2019/08/jpg-vs-jpeg.jpg"]
      }
    ]
  },
  "media": [
    {
      "originalSource": "https://kinsta.com/wp-content/uploads/2019/08/jpg-vs-jpeg.jpg",
      "alt": "VARIANT_IMAGE",
      "mediaContentType": "IMAGE"
    }
  ]
}


I have been able to update the product variant image only by running the productVariantUpdate mutation separately. This mutation requires you to retrieve the mediaId value, which I then use to assign the image to the product variant. Unfortunately, when trying to use the mediaId variable in the productUpdate mutation, I receive the following error:

{
  "errors": [
    {
      "message": "Internal error. Looks like something went wrong on our end.\nRequest ID: cd9eeda9-cb52-4171-bd7d-771e13757e7c (include this in support requests).",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "requestId": "cd9eeda9-cb52-4171-bd7d-771e13757e7c"
      }
    }
  ]
}

Here is the mutation I am running:

mutation productUpdateMutationMediaID($input: ProductInput!) {
  productUpdate(input: $input) {
    product {
      id
      media(first: 10) {
        edges {
          node {
            preview {
              image {
                id
              }
            }
          }
        }
        nodes {
          ... on MediaImage {
            id
            preview {
              image {
                url
                id
              }
            }
          }
          id
          preview {
            image {
              id
              url
            }
          }
        }
      }
      images(first: 10) {
        nodes {
          id
          url
        }
      }
      variants(first: 10) {
        nodes {
          image {
            id
            url
          }
          media(first: 10) {
            edges {
              node {
                id
              }
            }
          }
          productVariantComponents(first: 10) {
            nodes {
              productVariant {
                image {
                  id
                }
              }
            }
          }
        }
      }
    }
  }
}

And here are the variables I am passing into it:

{
  "input": {
      "id": "gid://shopify/Product/8971462902048",
      "variants": [
          {
            "mediaId": "gid://shopify/MediaImage/36397004882208"
          }
      ]
  }
}


Any help or clarification on why the mediaSrc is not working in my current iteration and how I can go about correctly using the mediaSrc variable would be greatly appreciated.

Thanks in advance for any help!

 

Reply 1 (1)

captainpryce
Shopify Partner
2 0 1

@ShopifyDevSup pinging support as I haven't heard back on this topic yet. Any help is appreciated