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:
- Obtain a Storefront API access token from the control panel.
- Use a GraphQL client such as Altair (opens in a new tab).
- Set the request URL to your store’s GraphQL endpoint (e.g.,
https://store-{store_hash}.mybigcommerce.com/graphql
). - Send an
Authorization
header with your Storefront API token. - Use the request body to send the
scripts
query.
The following example query will fetch the full set of 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
- BigCommerce GraphQL Storefront API Reference - Official API reference for the Storefront GraphQL API
- Scripts REST API - BigCommerce REST API endpoints for storefront script management
- Storefront Scripts Overview (Help Center) (opens in a new tab) - BigCommerce Support documentation on Script Manager
- Storefront API Authentication - Instructions for authenticating requests to the Storefront GraphQL API
- GraphQL Playground - Interactive GraphQL IDE for testing queries against the Storefront API