Ad

Shopify - Loading Data From An External REST API In A Liquid Template

- 1 answer

I need to load some data (A WordPress Menu) from an external REST API into my Shopify template. I'm assuming I need to use an App proxy to do this. I've looked through the documentation but I'm a little confused as to how to go about this.

Can anyone point me in the right direction?

Ad

Answer

I often use jquery with an ajax call to an api end point that either

  1. sends me back formatted html
  2. send me back json data that I parse and form the html via javascript.
    
        jQuery(window).load(function(){
            data = {};
                jQuery.ajax({
                    type: 'GET',
                    url: 'https://yourapp.herokuapp.com/yourendpoint.json',
                    data: data,
                    dataType: 'json',
                    success: function(data) { 
                        console.log(data);
                        $.each( data, function(i, item) {
                             console.log(item);
                            // do something with your data here
                        });
                    }
                });
        });
    

Ad
source: stackoverflow.com
Ad