> ## Documentation Index
> Fetch the complete documentation index at: https://betterdatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Shopify Integration

> Connect your Shopify store to any AI agent

Better Data provides a robust, production-ready integration for Shopify using the Storefront API. This allows any AI to search your catalog, check stock, and create draft orders.

## Prerequisites

* A Shopify store
* A Storefront Access Token (found in App settings -> Manage private apps)
* The `@commercegateway/commerce-gateway` package installed

## Setup

### 1. Initialize the Shopify Backend

```typescript theme={null}
import { ShopifyBackend } from '@commercegateway/commerce-gateway/shopify';

const shopify = new ShopifyBackend({
  domain: process.env.SHOPIFY_DOMAIN!, // e.g. mystore.myshopify.com
  accessToken: process.env.SHOPIFY_STOREFRONT_TOKEN!,
  apiVersion: '2024-01',
});
```

### 2. Connect to the Gateway

```typescript theme={null}
const gateway = new LLMGateway({
  backends: {
    products: shopify,
    cart: shopify,
    orders: shopify,
  },
});
```

## Features

### Product Search

Supports natural language searching, filtering by collections, and tag-based discovery.

### Real-time ATP

The backend automatically queries Shopify's internal inventory levels to provide accurate "Available to Promise" quantities to the LLM.

### Draft Orders

When a user is ready to checkout, the gateway creates a Shopify Draft Order and provides a secure link for the user to complete payment on your Shopify-hosted checkout page.

## Configuration

```typescript theme={null}
interface ShopifyConfig {
  domain: string;
  accessToken: string;
  apiVersion?: string;
  // Optional: Only include specific collections
  collections?: string[];
  // Optional: Map custom metafields to product attributes
  metafieldMap?: Record<string, string>;
}
```

## Troubleshooting

* **Permissions**: Ensure your Storefront Access Token has `unauthenticated_read_product_listings` and `unauthenticated_write_checkouts` scopes.
* **Throttling**: For very high traffic, Shopify might rate-limit the Storefront API. Consider using the [Better Data Cloud](/hosted/overview) for managed caching and shielding.
