FROM CACHE - en_header

Calling the Product Recommendations API from a store in dev mode

adamf
New Member
2 0 1

Seems that I can't access https://my-store.myshopify.com/recommendations/products.json?product_id=XXXXXXX&limit=4
Issue seems to be that the store being on a development platform, needs a password to access it.

I'm currently using Admin & Storefront API to build a site on a React/Next platform, but can't seem to get the recommendations from the graphql endpoint.
So will be querying using fetch and proxying to avoid CORS, when I do so, I get FetchError: invalid json response body at https://my-store.myshopify.com/password
So seems like the endpoint is redirecting to the password page.

Any help will be appreciated, I'd rather not make my own recommendation engine.

Replies 3 (3)
LuksyO
New Member
2 0 0
adamf
New Member
2 0 1

Hi @LuksyO 

I made my own solution. I'm using the graphql api to pull products using this query:

{
      products(first: 250, ${cursor}) {
        pageInfo {
          hasNextPage
        }
        edges {
          cursor
          node {
            vendor
            productType
            id
            title
            handle
            priceRangeV2 {
              maxVariantPrice {
                amount
                currencyCode
              }
              minVariantPrice {
                amount
                currencyCode
              }
            }
            featuredImage {
              originalSrc
              width
              height
            }
          }
        }
      }
    }

 

I use it to create a data array, then I filter that array to look for the same vendor or the same product type, something like this: 

dataArray
        .filter(
          (v, i, a) =>
            a.findIndex(
              (t) => JSON.stringify(t) === JSON.stringify(v)
            ) === i
        )
        .forEach((result) => {
          if (
            (result.node.vendor === vendor ||
              result.node.productType === productType) &&
            result.node.id !== productId
          )
            similar.push(result);
        });

 

You'll be hard pressed to find real support with Shopify.  The APIs are all over the place and seem half finished, but thats tech these days I guess.
There are heaps of work arounds for different things, but it's a lot of work.

 

LuksyO
New Member
2 0 0

Thank you so much @adamf for quick response, I thought of that, but I was hoping there was a cleaner way to do it, it is really irritating when you start building a custom solution with a technology and find out midway that half the questions about it is left unanswered ... and very basic features are not included... will never use shopify after this project again.