skip to Main Content

I am doing application for shopify using shopifyGraphQL storefront.

On the shopify website is using some theme. from the theme admin can sent banner and some advertisement message.

now i want to get those home page data on my mobile application (Data is set on the theme so question is how to get those data using APIs or any other way.)
using GraphQL API or any normal Rest API?

2

Answers


  1. In this case you could use the Shopify Storefront Graphql API.

    As I know you can’t query liquid code but maybe you could try to fetch the contents of your webpage via the fetchAPI?

    Reference:

    https://shopify.dev/docs/api/storefront

    https://shopify.dev/docs/custom-storefronts/building-with-the-storefront-api/products-collections/getting-started

    Login or Signup to reply.
  2. Shopify has a section rendering API that you can utilize to get selected sections. This API will return HTML of selected sections in a string format, so you can convert it to fit in your application.

    If you are using JS, you can use it like:

    export const renderSection = async (sectionId, path = '/') => {
      const hostName = 'https://your-host.com';
      try {
        const res = await fetch(
          hostName + path + `?sections=${sectionId}`
        );
        const result = await res.json();
        return result;
      } catch (error) {
        console.error(error);
      }
    };
    

    the returned JSON object would look like:

    {
      [sectionId]: '<div>...</div>',
    };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search