# Storefront API Querying the Storefront API. ```jsx import {useEffect, useState} from 'react'; import { useApi, reactExtension, List, ListItem, } from '@shopify/ui-extensions-react/checkout'; export default reactExtension( 'purchase.checkout.block.render', () => , ); function Extension() { const [data, setData] = useState(); const {query} = useApi(); useEffect(() => { query( `query ($first: Int!) { products(first: $first) { nodes { id title } } }`, { variables: {first: 5}, }, ) .then(({data, errors}) => setData(data)) .catch(console.error); }, [query]); return ( {data?.products?.nodes.map((node) => ( {node.title} ))} ); } ``` ```js import { extension, List, ListItem, } from '@shopify/ui-extensions/checkout'; export default extension( 'purchase.checkout.block.render', (root, {query}) => { query( `query ($first: Int!) { products(first: $first) { nodes { id title } } }`, { variables: {first: 5}, }, ) .then(({data}) => { const listItems = data?.products?.nodes.map((node) => root.createComponent( ListItem, undefined, node.title, ), ); root.appendChild( root.createComponent( List, undefined, listItems, ), ); }) .catch(console.error); }, ); ``` ## StandardApi The base API object provided to `purchase`, and `customer-account.order-status` extension targets. ### Docs_Standard_QueryApi ### query value: `(query: string, options?: { variables?: Variables; version?: StorefrontApiVersion; }) => Promise<{ data?: Data; errors?: GraphQLError[]; }>` - StorefrontApiVersion: '2022-04' | '2022-07' | '2022-10' | '2023-01' | '2023-04' | '2023-07' | 'unstable' Used to query the Storefront GraphQL API with a prefetched token. See [storefront api access examples](https://shopify.dev/docs/api/checkout-ui-extensions/apis/storefront-api) for more information. ## Related - [Targets](https://shopify.dev/docs/api/checkout-ui-extensions/targets) - [Components](https://shopify.dev/docs/api/checkout-ui-extensions/components) - [Configuration](https://shopify.dev/docs/api/checkout-ui-extensions/configuration) - [Tutorials](/apps/checkout) ## Examples Querying the Storefront API. You can access the [Storefront GraphQL API](https://shopify.dev/docs/api/storefront) using global `fetch()`. Ensure your extension can access the Storefront API via the [`api_access` capability](https://shopify.dev/docs/api/checkout-ui-extensions/configuration#api-access). ```jsx import {useEffect, useState} from 'react'; import { useApi, reactExtension, List, ListItem, } from '@shopify/ui-extensions-react/checkout'; export default reactExtension( 'purchase.checkout.block.render', () => , ); function Extension() { const {shop} = useApi(); const [data, setData] = useState(); useEffect(() => { const getProductsQuery = { query: `query ($first: Int!) { products(first: $first) { nodes { id title } } }`, variables: {first: 5}, }; const apiVersion = 'unstable'; fetch( `${shop.storefrontUrl}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); }, [shop]); return ( {data?.products?.nodes.map((node) => ( {node.title} ))} ); } ``` ```js import { extension, List, ListItem, } from '@shopify/ui-extensions/checkout'; export default extension( 'purchase.checkout.block.render', (root, {shop}) => { const apiVersion = 'unstable'; const getProductsQuery = { query: `query ($first: Int!) { products(first: $first) { nodes { id title } } }`, variables: {first: 5}, }; fetch( `${shop.storefrontUrl}api/${apiVersion}/graphql.json`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(getProductsQuery), }, ) .then((response) => response.json()) .then(({data}) => { const listItems = data?.products?.nodes.map((node) => root.createComponent( ListItem, undefined, node.title, ), ); root.appendChild( root.createComponent( List, undefined, listItems, ), ); }) .catch(console.error); }, ); ``` ## Examples Querying the Storefront API. You can access the [Storefront GraphQL API](https://shopify.dev/docs/api/storefront) using global `fetch()`. Ensure your extension can access the Storefront API via the [`api_access` capability](https://shopify.dev/docs/api/checkout-ui-extensions/configuration#api-access). ```jsx import {useEffect, useState} from 'react'; import { useApi, reactExtension, List, ListItem, } from '@shopify/ui-extensions-react/checkout'; export default reactExtension( 'purchase.checkout.block.render', () => , ); function Extension() { const {shop} = useApi(); const [data, setData] = useState(); useEffect(() => { const getProductsQuery = { query: `query ($first: Int!) { products(first: $first) { nodes { id title } } }`, variables: {first: 5}, }; const apiVersion = 'unstable'; fetch( `${shop.storefrontUrl}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); }, [shop]); return ( {data?.products?.nodes.map((node) => ( {node.title} ))} ); } ``` ```js import { extension, List, ListItem, } from '@shopify/ui-extensions/checkout'; export default extension( 'purchase.checkout.block.render', (root, {shop}) => { const apiVersion = 'unstable'; const getProductsQuery = { query: `query ($first: Int!) { products(first: $first) { nodes { id title } } }`, variables: {first: 5}, }; fetch( `${shop.storefrontUrl}api/${apiVersion}/graphql.json`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(getProductsQuery), }, ) .then((response) => response.json()) .then(({data}) => { const listItems = data?.products?.nodes.map((node) => root.createComponent( ListItem, undefined, node.title, ), ); root.appendChild( root.createComponent( List, undefined, listItems, ), ); }) .catch(console.error); }, ); ```