DocsAPIShopware Edge Function

    Shopware-Edge-Function-API

    VollstΓ€ndige API-Referenz fΓΌr die Shopware Edge Function mit 37 Endpunkten.

    Version 1.0
    23 Store API Endpoints
    14 Admin API Endpoints

    Inhalt

    Schnellstart

    Die Shopware Edge Function bietet ein sicheres API-Gateway fΓΌr alle Shopware-VorgΓ€nge. In 5 Minuten einsatzbereit.

    1. Installation in einem React-Projekt

    import { useShopwareAPI } from '@/hooks/useShopwareAPI';
    
    function ProductList() {
      const { getProducts, loading, error } = useShopwareAPI({
        projectId: 'your-project-uuid'
      });
      
      const [products, setProducts] = useState([]);
      
      useEffect(() => {
        getProducts({ limit: 12 }).then(setProducts);
      }, []);
      
      if (loading) return <div>Loading...</div>;
      if (error) return <div>Error: {error}</div>;
      
      return (
        <div className="grid grid-cols-4 gap-4">
          {products.map(product => (
            <ProductCard key={product.id} product={product} />
          ))}
        </div>
      );
    }

    Authentifizierung

    Die Edge Function verwendet ein mandantenfΓ€higes Modell mit projektbasierter Authentifizierung.

    Request Flow:
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  Client  │───▢│ Edge Function  │───▢│  DB Lookup   │───▢│  Shopware   β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                  β”‚                    β”‚                   β”‚
         β”‚  projectId       β”‚    shop_id         β”‚   credentials     β”‚
         β”‚                  β”‚    from projects   β”‚   from shops      β”‚
         β–Ό                  β–Ό                    β–Ό                   β–Ό
    projectId

    Identifiziert das Projekt und den verbundenen Shop

    userId

    Optional fΓΌr die Warenkorb-Persistenz (wird automatisch generiert, falls nicht angegeben)

    contextToken

    Shopware-Context-Token, wird automatisch verwaltet

    getProducts

    Produkte mit Pagination, Filter und Sortierung abrufen

    POST
    /functions/v1/shopware-api
    {
      "action": "getProducts",
      "api": "store",
      "projectId": "your-project-uuid",
      "data": {
        "limit": 24,
        "page": 1,
        "filter": [
          { "field": "active", "value": true }
        ],
        "sort": [
          { "field": "name", "order": "ASC" }
        ]
      }
    }

    TypeScript-Typen

    VollstΓ€ndige Typdefinitionen fΓΌr typsichere Entwicklung.

    types.ts

    // API Request Interface
    interface ShopwareAPIRequest {
      action: string;
      api?: 'store' | 'admin';
      projectId: string;
      userId?: string;
      contextToken?: string;
      data?: Record<string, unknown>;
    }
    
    // API Response Interface
    interface ShopwareAPIResponse<T = unknown> {
      success: boolean;
      data?: T;
      error?: string;
      contextToken?: string;
    }
    
    // Product Type
    interface ShopwareProduct {
      id: string;
      name: string;
      productNumber: string;
      translated?: {
        name?: string;
        description?: string;
      };
      calculatedPrice?: {
        unitPrice: number;
        totalPrice: number;
      };
      price?: Array<{
        gross: number;
        net: number;
        currencyId: string;
      }>;
      cover?: {
        media?: {
          url: string;
          thumbnails?: Array<{
            url: string;
            width: number;
            height: number;
          }>;
        };
      };
      stock: number;
      available: boolean;
      categories?: Array<{
        id: string;
        name: string;
      }>;
    }
    
    // Cart Type
    interface ShopwareCart {
      token: string;
      lineItems: Array<{
        id: string;
        referencedId: string;
        label: string;
        quantity: number;
        price: {
          unitPrice: number;
          totalPrice: number;
        };
      }>;
      price: {
        totalPrice: number;
        netPrice: number;
        taxStatus: string;
      };
    }
    
    // Category Type
    interface ShopwareCategory {
      id: string;
      name: string;
      translated?: { name: string };
      parentId?: string;
      children?: ShopwareCategory[];
    }

    Error Handling

    400

    Bad Request

    {
      "success": false,
      "error": "projectId required"
    }
    404

    Not Found

    {
      "success": false,
      "error": "Project not found or no shop connected"
    }
    500

    Server Error

    {
      "success": false,
      "error": "Shopware API error: Connection refused"
    }

    Anfragebegrenzungen und Leistung

    Supabase Limits

    Free Tier: 500.000 Invocations/Monat

    Pro Tier: 2 Mio Invocations/Monat

    Timeout: 60 Sekunden max

    Caching

    OAuth Token: 10 Minuten

    Context Token: 24 Stunden

    Product Cache: In-Memory (request-scoped)

    Weitere Ressourcen