Request to Fix Liquid snippet : Google API

Request to Fix Liquid snippet : Google API

-Charlo-007
Excursionist
25 0 0

Hey, I want to fetch bookbinding information using Google Book api and ISBN meta field in product page 

.

Check snippet code

 

{% comment %}
  This is a Liquid snippet for Shopify.
  It renders JavaScript code to fetch book binding information using the Google Books API.
{% endcomment %}

{% assign isbn = product.metafields.Neato.ISBN13 %}

<script>
  // Initialize ISBN variable with the value from product metafields
  const isbn = "{{ isbn }}";

  // Construct the API URL with the ISBN and API key
  const url = `https://www.googleapis.com/books/v1/volumes?q=isbn:${isbn}&key=AIzaSyAYWPf8pYcpd2H_-YWTK79F4b8kTRZMEx8`;

  // Make a GET request to the Google Books API
  fetch(url)
    .then(response => response.json())
    .then(data => {
      // Parse the response and extract book binding information
      const book = data.items[0]; // Assuming the first item is the desired book
      const binding = book.volumeInfo.printType; // Extracting binding info, assuming printType indicates the binding

      // Display book binding information
      console.log("Book Binding:", binding);
    })
    .catch(error => {
      console.error('Error fetching book binding:', error);
    });
</script>

 

 

 

Replies 0 (0)