GraphQL Storefront API
Storefront Scripts

GraphQL Storefront API: Scripts overview

Introduction

The GraphQL Storefront API's scripts query allows you to fetch storefront scripts configured in your BigCommerce control panel. This feature is designed to help merchants and developers programmatically retrieve both inline and external scripts that are executed on the storefront, providing visibility and control over scripts used for analytics, integrations, and custom storefront functionality.

What is a storefront script

A storefront script is a snippet of JavaScript or an external script URL that can be injected into your storefront pages. Storefront scripts are managed per storefront through the BigCommerce control panel and can be used for a wide variety of purposes, such as analytics tracking, integrations with third-party services, or adding custom functionality to storefront pages.

Prerequisites

Before using the scripts query, ensure you have the following:

  • A BigCommerce store with scripts configured via the control panel
  • A valid Storefront API access token with sufficient permissions to query storefront data

To learn more about authenticating GraphQL Storefront API requests, see the Authentication and Example Requests.

Getting started

The scripts query provides a simple way to retrieve all scripts set up for your storefront. You can use this query to audit which scripts are currently active, fetch metadata such as consent category and visibility, and distinguish between inline and external scripts. The API supports filtering, pagination, and provides detailed information about each script, including its location on the page (e.g., <head>, <footer>), integrity hashes, and type.

Begin with the following steps:

  1. Obtain a Storefront API access token from the control panel.
  2. Use a GraphQL client such as Altair (opens in a new tab).
  3. Set the request URL to your store’s GraphQL endpoint (e.g., https://store-{store_hash}.mybigcommerce.com/graphql).
  4. Send an Authorization header with your Storefront API token.
  5. Use the request body to send the scripts query.

The following example query will fetch the full set of storefront scripts.

Example query: Get storefront scripts
query Scripts {
  site {
    content {
      scripts {
        edges {
          node {
            ... on InlineScript {
              scriptTag
              entityId
              consentCategory
              visibility
              integrityHashes {
                hash
              }
              location
            }
            ... on SrcScript {
              src
              entityId
              consentCategory
              visibility
              integrityHashes {
                hash
              }
              location
            }
          }
        }
      }
    }
  }
}

Resources

Did you find what you were looking for?