How to get public product page url from orders API?

I am using the orders REST API to get shopify order information in a custom service. The orders object contains an array of line_items, the line_items contain the product_id and variant_id of each purchased item.

However, I can’t figure out how to construct a public facing url to the actual product. Am I missing something here? I would expect {store}/products/{product_id} to redirect there but it doesn’t and the handle isn’t included in the orders object from what I can tell.

How do I get this information without having to call another API to get the handle, is this possible?

Hi @ahurlburt

It’s not possible to do this with the current Rest API.

But it’s achievable if you use GraphQL for this query.

Something like:

query {
  order(id:"gid://shopify/Order/1111111111") {
    lineItems(first:10) {
      pageInfo {
        hasNextPage
        hasPreviousPage
      }
      edges {
        cursor
        node {
          id
          name
          product {
            handle
          }
        }
      }
    }
  }
}

Using the Shopify GraphiQL App is always my first port of call for this as you have documentation in the right-hand column and autocomplete within the editor window by default.

1 Like

Thank you. I figured the graphql api would support this but was hoping for a rest solution since my application is already integrated with shopify using rest. But this does appear the only solution.

Thanks as well for the link to the graphql app, that is handy.