"Internal error" when querying MediaImage node on the Storefront API

Storefront API Version: 2021-10.

What I’m trying to do: Query MediaImage data associated with a product metafield.

After :

  1. Creating a product metafield with Shopify’s new metafields interface
  2. Using the Admin API to expose the metafield to the Storefront API
  3. Uploading an image as the metafield’s value for a particular product

I use the following query to request the image data contained in the metafield:

query {
  product(handle: "high-roller-skates") {
    handle
    metafields(first: 5) {
      edges {
        node {
          namespace
          key
          value
        }
      }
    }
  }
}

which returns:

{
  "data": {
    "product": {
      "handle": "high-roller-skates",
      "metafields": {
        "edges": [
          {
            "node": {
              "namespace": "my_fields",
              "key": "bearings",
              "value": "gid:\/\/shopify\/MediaImage\/20867885990023"
            }
          }
        ]
      }
    }
  }
}

Using the Shopify Global ID given in the metafield’s value, I run a second query for the actual image data:

{
  node(id: "gid://shopify/MediaImage/20867885990023") {
    ... on MediaImage {
      id
      image {
        altText
        originalSrc
      }
      mediaContentType
    }
  }
}

Unfortunately, this results in an INTERNAL_SERVER_ERROR:

{
  "errors": [
    {
      "message": "Internal error. Looks like something went wrong on our end.\nRequest ID: fc94c2e8-9b59-4d8e-9eb3-2eb2a6e49f78 (include this in support requests).",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "requestId": "fc94c2e8-9b59-4d8e-9eb3-2eb2a6e49f78"
      }
    }
  ]
}

I’ve tried using the base-64 encoded version of the global ID (“Z2lkOi8vc2hvcGlmeS9NZWRpYUltYWdlLzIwODY3ODg1OTkwMDIz”), but this results in the same INTERNAL_SERVER_ERROR.

Is this a bug in the Storefront API, or is there another issue at play?

This is a bug on Shopify’s side as you suspected. I’ve created an issue internally and it should hopefully be fixed soon.

Thank you for the very detailed post.

Thank you so much for the response and for creating the bug ticket, @swalkinshaw !

The Storefront API bug has been fixed. I’m now able to query for MediaImage nodes:

Thanks for fixing this bug!

Bumping because this is the only place I found the correct answer to getting MediaImage from a GraphQL API query. Thanks OP :slight_smile: Here’s mine:

{% capture query %}
	query {
		node(id: "gid://shopify/MediaImage/38270889722113") {
    ... on MediaImage {
      id
      image {
        altText
        originalSrc
      }
      mediaContentType
      }
    }
	}
{% endcapture %}
{% assign result = query | shopify %}
{% log result %}

I should say, getting a URL from a MediaImage gid link, via a GraphQL API query.