Using personalized data for product description (via api)

Using personalized data for product description (via api)

thewa
Shopify Partner
3 0 0

I would like to take customer information (e.g. for logged in customers, a metafield), and based on that information, show a product description.

I want to use a customer metafield information, together with a product sku, and send them to an endpoint, where I will calculate specific details for that particular user and product. I want to show those information in the product description.

 

I thought this is possible by simply using JS and liquid - but that would expose a security risk as I would have to use my api key - and I would therefore prefer another solution.

What would the best and most scalable way be to implement this? Is it possible at all?

Reply 1 (1)

Gift-o-the-Jab
Navigator
366 23 95

Complex one. You could save additional metadata for customers using Metafields along with the Shopify API by creating a private app. You didn't say if you have already done so?

 

If you want to protect your API keys, maybe with a separate server to run the computations. Or develop a middleware API on your secure server that will communicate with Shopify's API and your custom endpoint for calculation, taking SKU and customer metafield as input, fetch the necessary data, send the data to your endpoint for calculation, and return the response. Easy-peasy-lemon-squeezy...NOT! 😉

 

In your storefront, use Liquid and JavaScript to call your Middleware API. The product description can be dynamically updated based on the response from your Middleware API with some token-based authentication between your frontend and your Middleware API.

 

Use a webhook or background job to pre-calculate the specific details and store them in your server or Shopify's Metafields to avoid delays in page loading due to API calls.

 

Here a possible flow:

  • User visits your product page
  • JavaScript in the product page makes a request to the Middleware API with customer ID and product SKU
  • API fetches data using Private App and sends data to the custom endpoint which returns specific details
  • Middleware returns details to the frontend which updates product description based on the returned details.

Hope that will get you in the right direction... Any further questions - consult a Shopify expert.