Storefront APIAPI
Querying the Storefront API.
Anchor to standardapiStandardApi
The base API object provided to this and other customer-account
extension targets.
- Anchor to queryquery<Data = unknown, Variables = { [key: string]: unknown; }>(query: string, options?: { variables?: Variables; version?: StorefrontApiVersion; }) => Promise<{ data?: Data; errors?: GraphQLError[]; }>required
Used to query the Storefront GraphQL API with a prefetched token.
See storefront api access examples for more information.
Docs_Standard_QueryApi
- query
Used to query the Storefront GraphQL API with a prefetched token. See [storefront api access examples](/docs/api/customer-account-ui-extensions/apis/storefront-api#examples) for more information.
<Data = unknown, Variables = { [key: string]: unknown; }>(query: string, options?: { variables?: Variables; version?: StorefrontApiVersion; }) => Promise<{ data?: Data; errors?: GraphQLError[]; }>
export interface Docs_Standard_QueryApi
extends Pick<StandardApi<any>, 'query'> {}
StorefrontApiVersion
Union of supported storefront API versions
'2022-04' | '2022-07' | '2022-10' | '2023-01' | '2023-04' | '2023-07' | '2024-01' | '2024-04' | '2024-07' | '2024-10' | '2025-01' | '2025-04' | 'unstable' | '2025-07' | '2025-10'
GraphQLError
GraphQL error returned by the Shopify Storefront APIs.
- extensions
{ requestId: string; code: string; }
- message
string
export interface GraphQLError {
message: string;
extensions: {
requestId: string;
code: string;
};
}
Access the Storefront API with query
Preact
examples
Access the Storefront API with query
description
You can access the [Storefront GraphQL API](/docs/api/storefront) via the `query()` helper function. Ensure your extension can use this API by [enabling the `api_access` capability](/docs/api/customer-account-ui-extensions/configuration#api-access).
Preact
import '@shopify/ui-extensions/preact'; import {render} from 'preact'; import {useEffect, useState} from 'preact/hooks'; export default async () => { render(<Extension />, document.body); }; function Extension() { const [data, setData] = useState({}); useEffect(() => { shopify .query( `query ($first: Int!) { products(first: $first) { nodes { id title } } }`, { variables: {first: 5}, }, ) .then(({data, errors}) => { setData(data); }) .catch(console.error); }, [setData]); return ( <s-unordered-list> {data?.products?.nodes.map((node) => { return ( <s-list-item id={node.id} key={node.id}> {node.title} </s-list-item> ); })} </s-unordered-list> ); }
Anchor to examplesExamples
Anchor to example-accessing-the-storefront-api-with-fetch()Accessing the Storefront API with fetch()
You can access the Storefront GraphQL API using global fetch()
.
Ensure your extension can access the Storefront API via the capability.
Accessing the Storefront API with fetch()
Preact
examples
Accessing the Storefront API with fetch()
description
You can access the [Storefront GraphQL API](/docs/api/storefront) using global `fetch()`. Ensure your extension can access the Storefront API via the [`api_access` capability](/docs/api/customer-account-ui-extensions/configuration#api-access).
Preact
import '@shopify/ui-extensions/preact'; import {render} from 'preact'; import {useEffect, useState} from 'preact/hooks'; export default async () => { render(<Extension />, document.body); }; function Extension() { const [data, setData] = useState(); useEffect(() => { const getProductsQuery = { query: `query ($first: Int!) { products(first: $first) { nodes { id title } } }`, variables: {first: 5}, }; const apiVersion = 'unstable'; fetch( `shopify://storefront/api/${apiVersion}/graphql.json`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(getProductsQuery), }, ) .then((response) => response.json()) .then(({data, errors}) => setData(data)) .catch(console.error); }, []); return ( <s-unordered-list> {data?.products?.nodes.map((node) => ( <s-list-item key={node.id}> {node.title} </s-list-item> ))} </s-unordered-list> ); }