liquid api shopify

PHOTO EMBED

Wed Dec 01 2021 08:16:02 GMT+0000 (Coordinated Universal Time)

Saved by @akairo0902 #vue

  const productQuery = () => `
  query {
    shop {
      products( first: 10) {
        edges{
          node {
            id
            handle
            title
	
            variants(first: 10){
              edges{
                node{
                  title
              }
            }
          }
        }
      }  
    }
  }
}
`;


const STOREFRONT_ACCESS_TOKEN =  "xxxxxxxx"

const GRAPHQL_URL = "https://xxxxxxxxx.myshopify.com/api/2021-10/graphql.json"


const GRAPHQL_BODY  = () => {
	return {
	'async': true,
	'crossDomain': true,
	'method': 'POST',
	'headers': {
		'X-Shopify-Storefront-Access-Token': STOREFRONT_ACCESS_TOKEN,
		'Content-Type': 'application/graphql',
	},
	'body': productQuery()
	};
}

fetch(GRAPHQL_URL, GRAPHQL_BODY())
        .then(res => res.json())
	.then(products => {
		console.log('products', products)
	})
content_copyCOPY