Download file from API

Solved

Download file from API

VRANDED
Shopify Partner
4 1 0

Hi,

 

I'm trying to download the data of some client metafields using "Make.com". But I'm having problems with a "file type" metafield.

I'm receiving just a Global ID URL. How is it posible to "translate" the "Global ID URL" to a "normal URL" that I can use on any browser or Make.com?

 

These are the only 2 URLs I'm receiving from the metafield:

  • Value: gid://shopify/MediaImage/32971699323189
  • admin_graphql_api_id: gid://shopify/Metafield/28466662342965

Thank you very much

Accepted Solution (1)
VRANDED
Shopify Partner
4 1 0

This is an accepted solution.

hi!

 

With your help and a lot of tries, I've found the solution:

query {
  metafield(id: "gid://shopify/Metafield/28466662342965") {    
    reference{
        ...on MediaImage{
          image {
            url
          }
        }
      }
  }
}

Thank you

View solution in original post

Replies 5 (5)

tyler-rowsell
Shopify Staff
30 5 3

 

Hey There!

 

The answer would depend on where you're reading the data from.

 

If you're reading the data in the liquid API you would need to retrieve the references from the metafield value.

{% if metafield.type == "file_reference" %}
  {{ metafield.value.src }}
{% endif %}

 

If you're reading from the admin api you can request the reference value.

query Product{
  product(id: "gid://shopify/Product/7989949431830"){
    metafield(namespace: "custom", key: "image"){
      id
      reference{
        ...on MediaImage{
          image {
            url
          }
        }
      }
    }
  }
}

 

To learn more visit the Shopify Help Center or the Community Blog.

VRANDED
Shopify Partner
4 1 0

Hi Tyler,

 

The file is a client metafield type "file". What should be the Query in this case?

 

Thanks

tyler-rowsell
Shopify Staff
30 5 3

The queries above should do the trick. 

To learn more visit the Shopify Help Center or the Community Blog.

VRANDED
Shopify Partner
4 1 0

Hi Tyle,

 

I'm using the Shopify REST API. Which should be the endpoint URL using Shopify REST API?

 

Thank you

VRANDED
Shopify Partner
4 1 0

This is an accepted solution.

hi!

 

With your help and a lot of tries, I've found the solution:

query {
  metafield(id: "gid://shopify/Metafield/28466662342965") {    
    reference{
        ...on MediaImage{
          image {
            url
          }
        }
      }
  }
}

Thank you