Making BigCommerce GraphQL query with JS

While we recommend adding your GraphQL queries to stencil template front matter wherever possible. You can also make requests from JavaScript within your theme or in Script Manager. 

See this example from BigCommerce:

fetch('/graphql', {
    method: 'POST',
    credentials: 'same-origin',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {{ settings.storefront_api.token }}'
    },
    body: JSON.stringify({
        query: `
        query MyFirstQuery {
        site {
            settings {
            storeName
            }
            products {
            edges {
                node {
                  name
                  sku
                  prices {
                    retailPrice {
                      value
                      currencyCode
                    }
                    price {
                      value
                      currencyCode
                    }
                  }
                }
              }
            }
          }
        }
        `
    }),
})
.then(res => res.json())
.then(json => console.log(json));<br>
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us