collection url

jbarlow
New Member
4 0 0

Is there a way to get the url for a collection from the GraphQL API?  I'm making an app and was able to get urls for products, but not for collections yet.

https://shopify.dev/docs/admin-api/graphql/reference/products-and-collections/collection

0 Likes
syf_
Shopify Staff
Shopify Staff
92 20 15

Hi @jbarlow,

I do not know if there's a way to get the complete URL of a collection using the GraphQL API but I believe you can build it using thehandle field of a collection. See below

 

 

query collectionHandles{
  collections(first:5){
    edges{
      node{
        handle
      }
    }
  }
}

 

 

Using the handle, you can reconstruct the url as follows: {domain}/collections/{handle}

This is only a workaround, and I cannot guarantee that it works all the time, though I think it should.

Best,
Seth.

syf_ | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
jbarlow
New Member
4 0 0

Hi @syf_ ,

Thank you for the reply.  It would be a great addition to the api to have the collection url.  I also converged on the approach you mentioned and share the concern that it may not be reliable, though I haven't seen it fail yet.

0 Likes