How to get public product page url from orders API?

Solved

How to get public product page url from orders API?

ahurlburt
Shopify Partner
19 0 3

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?

Adam Hurlburt | Cofounder & CTO of Sellify: a CRM & B2B Solution For Shopify Stores

If you found this suggestion helpful, please let me know by giving it a like or marking it as a solution.
Accepted Solution (1)

SB_90
Shopify Partner
216 52 69

This is an accepted solution.

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.

View solution in original post

Replies 2 (2)

SB_90
Shopify Partner
216 52 69

This is an accepted solution.

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.

ahurlburt
Shopify Partner
19 0 3

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.

Adam Hurlburt | Cofounder & CTO of Sellify: a CRM & B2B Solution For Shopify Stores

If you found this suggestion helpful, please let me know by giving it a like or marking it as a solution.