Token Storefront
/graphql-storefrontL'API GraphQL Storefront permet d'interroger les données storefront pour le commerce headless, les thèmes Stencil et les expériences d'achat personnalisées. Elle fournit un accès en lecture seule aux données catalogue, p
<overview>
The GraphQL Storefront API enables querying storefront data for headless commerce, Stencil themes, and custom shopping experiences. It provides read-only access to catalog data, carts, checkout, and customer information. For mutations and admin operations, use REST APIs.
</overview>
<endpoint>
POST https://{store_domain}/graphql
Authorization: Bearer {storefront_token}
Content-Type: application/jsonReplace {store_domain} with your storefront URL (e.g., store.mybigcommerce.com or custom domain).
</endpoint>
<authentication>
<token_types>
Storefront Token:
- Anonymous shopper queries
- Public catalog data
- Create via REST API
Customer Impersonation Token:
- Customer-specific data (wishlists, account info)
- Server-to-server requests
- More secure, limited exposure
</token_types>
<creating_tokens>
# Storefront Token
POST /v3/storefront/api-token
{
"channel_id": 1,
"expires_at": 1893456000,
"allowed_cors_origins": ["https://your-site.com"]
}
# Customer Impersonation Token
POST /v3/storefront/api-token-customer-impersonation
{
"channel_id": 1,
"expires_at": 1893456000
}</creating_tokens>
<best_practices>
- Rotate tokens regularly
- Use short expiration for client-side tokens
- Customer impersonation tokens for server-side only
- Respect Principle of Least Privilege
</best_practices>
</authentication>
<common_queries>
<get_products>
query GetProducts($first: Int!) {
site {
products(first: $first) {
edges {
node {
entityId
name
sku
path
prices {
price {
value
currencyCode
}
salePrice {
value
}
}
defaultImage {
url(width: 500)
}
variants {
edges {
node {
entityId
sku
inventory {
isInStock
aggregated {
availableToSell
}
}
}
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}</get_products>
<get_category>
query GetCategory($path: String!) {
site {
route(path: $path) {
node {
... on Category {
entityId
name
description
products {
edges {
node {
entityId
name
prices {
price {
value
}
}
}
}
}
}
}
}
}
}</get_category>
<search_products>
query SearchProducts($searchTerm: String!) {
site {
search {
searchProducts(filters: {searchTerm: $searchTerm}) {
products {
edges {
node {
entityId
name
path
}
}
}
}
}
}
}</search_products>
<get_customer>
Requires customer impersonation token or logged-in customer context:
query GetCustomer {
customer {
entityId
email
firstName
lastName
company
customerGroupId
addresses {
edges {
node {
entityId
firstName
lastName
address1
city
stateOrProvince
postalCode
countryCode
}
}
}
}
}</get_customer>
</common_queries>
<cart_operations>
<create_cart>
mutation CreateCart($input: CreateCartInput!) {
cart {
createCart(input: $input) {
cart {
entityId
lineItems {
physicalItems {
entityId
productEntityId
variantEntityId
name
quantity
extendedSalePrice {
value
}
}
}
}
}
}
}Variables:
{
"input": {
"lineItems": [
{
"productEntityId": 123,
"variantEntityId": 456,
"quantity": 2
}
]
}
}</create_cart>
<addtocart>
mutation AddToCart($input: AddCartLineItemsInput!) {
cart {
addCartLineItems(input: $input) {
cart {
entityId
lineItems {
physicalItems {
entityId
name
quantity
}
}
}
}
}
}</addtocart>
<get_cart>
query GetCart($entityId: String!) {
site {
cart(entityId: $entityId) {
entityId
currencyCode
isTaxIncluded
baseAmount {
value
}
discountedAmount {
value
}
amount {
value
}
lineItems {
physicalItems {
entityId
name
quantity
extendedSalePrice {
value
}
}
digita