Return media id from productCreateMedia when using GraphQL

Hello,

I am trying to get back the id of the media file that I have assigned to a product each time. I create the staged upload and then use the “productCreateMedia” mutation which works fine but I need to get the media id so that when it is updated on our system I can update the media file on Shopify.

I am using the code below on Node JS and I cannot figure out how to get the block to return the media id so that I can use it:

const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
“query”: `mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {
productCreateMedia(media: $media, productId: $productId) {
media {
alt
mediaContentType
status
}
mediaUserErrors {
field
message
}
product {
id
title
}

}

}`,
“variables”: {
“media”: {
“alt”: String(asset.fileType),
“mediaContentType”: String(asset.fileType),
“originalSource”: String(asset.resourceUrl)
},
“productId”: “gid://shopify/Product/” + shopifyProductId
},
},
});

add a MediaImage Fragment to media:
mutation createProductImage($media: [CreateMediaInput!]!, $productId: ID!) {
productCreateMedia(media: $media, productId: $productId) {
media {
alt
status
mediaContentType
… on MediaImage{
id
}

}
mediaUserErrors {
field
message
}
product {
id
}
}
}