bagisto/bagisto-api
REST and GraphQL API layer for Bagisto 2.3.8+, built on API Platform. Quickly install via Composer and an Artisan installer to get API docs, GraphQL Playground, and shop/admin endpoints for e‑commerce integrations and extensions.
## Getting Started
This package is now a **fully-fledged eCommerce API platform** built on Laravel, API Platform, and GraphQL. For new developers, start with:
1. **Installation** (updated for v1.0.4):
```bash
composer require bagisto/api-platform:^1.0.4
php artisan bagisto-api-platform:install --force # Added --force flag for safer upgrades
php artisan migrate --seed # New seeders for sample data
The install command now includes database seeders for pre-populated test data (customers, products, orders).
First Use Case (updated):
CustomerOrderProvider with v1.0.4's enhanced filtering:
$orders = $this->customerOrderProvider->getOrders($customerId, [
'filter' => ['status' => ['eq' => 'completed']],
'sort' => ['-created_at']
]);
/graphiql (fixed typo in docs) to explore new v1.0.4 queries:
query {
customerOrders(filter: {status: {eq: "completed"}}) {
edges {
node {
id
orderNumber
total
# New field: paymentStatus
paymentStatus
}
}
}
}
/api/seed-data endpoint to fetch sample payloads for testing:
curl -X GET http://your-app.test/api/seed-data
Key Configs (updated):
config/api-platform.php for new OpenAPI/Swagger v3.1.0 compliance.config/api-platform-vendor.php for rate limit overrides (now supports per-endpoint limits).Accept-Language now supports region-specific fallbacks (e.g., en-US,en;q=0.9).config/api-platform-webhooks.php for event-driven integrations.Customer-Centric APIs (updated):
CancelOrderProcessor with new cancellation reasons (v1.0.4):
$processor = new CancelOrderProcessor();
$result = $processor->process(new CancelOrderInput(
$orderId,
$customerId,
reason: 'customer_request' // New enum: 'customer_request', 'stock_unavailable', 'fraud'
));
ReorderProcessor with new includeTaxes flag:
$this->reorderProcessor->execute(new ReorderInput(
$orderId,
$customerId,
includeTaxes: true
));
CustomerProfileOutput with new address validation:
$profile = $this->customerProfileHelper->getProfile($customerId, validateAddresses: true);
Catalog & Storefront (updated):
includeMedia flag:
GET /api/locales?includeMedia=true
Accept-Language: fr_FR
timezone parameter (v1.0.4):
query {
bookingSlots(productId: "123", timezone: "America/New_York") {
availableSlots
}
}
version parameter:
$page = $this->pageProvider->getByUrlKey('about-us', version: 'draft');
Cart/Wishlist/Compare (updated):
CartTokenProcessor with new mergeStrategy option:
$mergedCart = $this->cartTokenProcessor->merge($token1, $token2, strategy: 'prioritize_latest');
Strategies: prioritize_latest, prioritize_first, merge_quantities.MoveWishlistToCartProcessor with new preserveQuantities flag:
$this->moveWishlistToCartProcessor->execute(
new MoveWishlistToCartInput($wishlistId, $customerId, preserveQuantities: false)
);
CompareProductProvider for multi-product comparisons:
$comparison = $this->compareProductProvider->getComparison([$productId1, $productId2]);
Infrastructure (updated):
$orders = $this->customerOrderProvider->getOrders($customerId, [
'pagination' => [
'type' => 'cursor',
'pageSize' => 20,
'includeMetadata' => true
]
]);
php artisan bagisto-api-platform:cache:clear --group=orders
Groups: orders, products, customers, all.Webhooks (new in v1.0.4):
WebhookService:
$webhook = $this->webhookService->create([
'url' => 'https://your-webhook-endpoint.com',
'events' => ['order.placed', 'inventory.low'],
]);
$this->webhookService->trigger('order.placed', $order);
include directives (v1.0.4):
query {
customerOrders(include: [shipments, invoices, items]) {
edges {
node {
id
shipments { trackingNumber }
invoices { pdfUrl }
}
}
}
}
Accept-Language headers for catalog data. Use new region-specific fallbacks:
Accept-Language: en-US,en;q=0.9,fr;q=0.8
api-platform-vendor.php:
'rate_limits' => [
'storefront/products' => '60|minute',
'storefront/cart' => '120|minute',
],
WebhookEvent class for type-safe event handling:
use Bagisto\ApiPlatform\Events\WebhookEvent;
event(new WebhookEvent('order.placed', $order));
Breaking Changes (updated):
CartTokenProcessor extensions. Use the new mergeStrategy to avoid silent failures.$this->wishlistProvider->addItem($wishlistId, $productId, skipValidation: true);
.env overrides:
API_PLATFORM_RATE_LIMIT_STOREFRONT_PRODUCTS=100|minute
API_PLATFORM_RATE_LIMIT_STOREFRONT_CART=200|minute
http:// only in development:
$webhook = $this->webhookService->create(['url' => 'http://localhost:3000']);
Common Bugs (updated):
null translations if active status isn’t set. Use:
$product->setTranslationFallback(true)->setActive(true);
preserveQuantities (default: true). Reset cart first if needed:
$this->cartService->clear($customerId);
# Example of a validated query
query {
customerOrders(filter: {
How can I help you explore Laravel packages today?