Pulling external data onto a shopify custom created page

Solved
Highlighted
Tourist
9 0 0

Hi, 

I tried looking or a direct solution on this and couldn't find.   Thought I'll post here.  We have some external data we want to pull in on a new custom page in shopify instead of customers jumping from site to site.    This database resides externally on a sql server database.     I understand we can use APIs to pull information out of shopify.   But, can we take advantage of shopify scripting /ruby script or javascript on  a new html page, so it can connect to an external database and run a query and get that info to a new shopify page?

0 Likes
Highlighted
Shopify Partner
25 0 15

We have the exact question.  Did you ever get this worked out?

1 Like
Highlighted
Pathfinder
83 4 11

I also have that same question and would love to have some feedback from anyone if this is possible. I can see that WooCommerce does have this functionality and it would be good to know how to do it in Shopify as well. Here is the link to how this is done in WooCommerce.

 

0 Likes
Pathfinder
83 4 11

This is an accepted solution.

It turns out this is very easy to do within Shopify. You can use fetch to reach out to an external API and this returns data to inside the Shopify app.

Here is an example that I have working inside my server.js file which reaches out to the external API on github that returns users. The user data is returned to Shopify and printed out in the console in this example. 

//call the fetch function
async function getData()
    {
        //await the response of the fetch call
               let response = await fetch('https://api.github.com/users');
        //proceed once the first promise is resolved.
       let data = await response.json()
        //proceed only when the second promise is resolved
        return data;
    }
//call getData function
getData()
.then(data => console.log(data));//log the data
1 Like