---
name: Shopify Store
priority: 2
keywords: shopify, shop, شوبيفاي, متجر شوبيفاي, store, products, orders, customers, draft order, abandoned cart, fulfillment
---

# Shopify Integration

## متى تستخدم
أي عملية على متجر Shopify — products, orders, customers, draft orders, fulfillments, refunds.

## المصادقة
- **Custom App** (الأبسط): من Settings → Apps → Develop apps → Configure → install → نسخ Admin API access token.
- خزّن: `SHOPIFY_TOKEN=shpat_...` و `SHOPIFY_DOMAIN=yourstore.myshopify.com`
- Base: `https://$SHOPIFY_DOMAIN/admin/api/2024-10`

## العمليات الأساسية

### Orders
```bash
# آخر 50 طلب
exec_command "curl -s -H 'X-Shopify-Access-Token: $SHOPIFY_TOKEN' \
  'https://$SHOPIFY_DOMAIN/admin/api/2024-10/orders.json?status=any&limit=50'"

# طلب واحد بتفاصيل
exec_command "curl -s -H 'X-Shopify-Access-Token: $SHOPIFY_TOKEN' \
  'https://$SHOPIFY_DOMAIN/admin/api/2024-10/orders/$ORDER_ID.json'"

# تحديث طلب (الإلغاء)
exec_command "curl -s -X POST -H 'X-Shopify-Access-Token: $SHOPIFY_TOKEN' -H 'Content-Type: application/json' \
  -d '{\"reason\":\"customer\",\"refund\":true}' \
  'https://$SHOPIFY_DOMAIN/admin/api/2024-10/orders/$ORDER_ID/cancel.json'"

# Fulfillment (شحن)
exec_command "curl -s -X POST -H 'X-Shopify-Access-Token: $SHOPIFY_TOKEN' -H 'Content-Type: application/json' \
  -d '{\"fulfillment\":{\"location_id\":$LOC_ID,\"tracking_number\":\"SMSA-XXX\",\"tracking_company\":\"SMSA Express\",\"notify_customer\":true}}' \
  'https://$SHOPIFY_DOMAIN/admin/api/2024-10/orders/$ORDER_ID/fulfillments.json'"
```

### Products + Inventory
```bash
# قائمة المنتجات
exec_command "curl -s -H 'X-Shopify-Access-Token: $SHOPIFY_TOKEN' \
  'https://$SHOPIFY_DOMAIN/admin/api/2024-10/products.json?limit=50'"

# إنشاء منتج
exec_command "curl -s -X POST -H 'X-Shopify-Access-Token: $SHOPIFY_TOKEN' -H 'Content-Type: application/json' \
  -d '{\"product\":{\"title\":\"عطر العود الفاخر\",\"vendor\":\"TaseesAI\",\"product_type\":\"Perfume\",\"variants\":[{\"price\":\"450.00\",\"sku\":\"PERF-OUD-001\",\"inventory_management\":\"shopify\",\"inventory_quantity\":100}]}}' \
  'https://$SHOPIFY_DOMAIN/admin/api/2024-10/products.json'"

# تحديث مخزون
exec_command "curl -s -X POST -H 'X-Shopify-Access-Token: $SHOPIFY_TOKEN' -H 'Content-Type: application/json' \
  -d '{\"location_id\":$LOC_ID,\"inventory_item_id\":$ITEM_ID,\"available\":50}' \
  'https://$SHOPIFY_DOMAIN/admin/api/2024-10/inventory_levels/set.json'"
```

### Draft orders (لـcustom invoicing)
```bash
exec_command "curl -s -X POST -H 'X-Shopify-Access-Token: $SHOPIFY_TOKEN' -H 'Content-Type: application/json' \
  -d '{\"draft_order\":{\"line_items\":[{\"variant_id\":$VARIANT_ID,\"quantity\":2}],\"customer\":{\"id\":$CUSTOMER_ID},\"use_customer_default_address\":true}}' \
  'https://$SHOPIFY_DOMAIN/admin/api/2024-10/draft_orders.json'"
# الرد فيه invoice_url — شارك مع العميل.
```

### Customers
```bash
# بحث عميل بالإيميل
exec_command "curl -s -H 'X-Shopify-Access-Token: $SHOPIFY_TOKEN' \
  'https://$SHOPIFY_DOMAIN/admin/api/2024-10/customers/search.json?query=email:ahmed@example.com'"
```

## أنماط شائعة

### Abandoned cart recovery
```bash
exec_command "curl -s -H 'X-Shopify-Access-Token: $SHOPIFY_TOKEN' \
  'https://$SHOPIFY_DOMAIN/admin/api/2024-10/checkouts.json?status=open&created_at_min=$(date -v-24H -u +%Y-%m-%dT%H:%M:%SZ)'"
# → استخرج الـemail + recovery_url + line items
# → ابعث WhatsApp/email reminder
```

### Top selling هذا الشهر
GET `/orders.json?financial_status=paid&created_at_min=...` → group بـline_items.title → sort.

### Webhook setup
عشان تستلم events real-time:
```bash
exec_command "curl -s -X POST -H 'X-Shopify-Access-Token: $SHOPIFY_TOKEN' -H 'Content-Type: application/json' \
  -d '{\"webhook\":{\"topic\":\"orders/create\",\"address\":\"https://yourdomain.com/webhooks/shopify\",\"format\":\"json\"}}' \
  'https://$SHOPIFY_DOMAIN/admin/api/2024-10/webhooks.json'"
```

## أمثلة
- "كم order اليوم في Shopify" → GET orders بـcreated_at_min=today.
- "اشحن الطلب #1234 برقم تتبع SMSA-XXX" → POST fulfillment.
- "أنشئ draft order لأحمد بمنتجين" → POST draft_orders، شارك invoice_url.
- "كم العملاء اللي اشتروا أكثر من 1000 ر.س هذا العام" → orders بـtotal_price > 1000، group بـcustomer_id, count.

## القواعد الذهبية
- ❌ **ممنوع** delete product/order — استخدم archive بدل.
- ❌ **rate limit**: 2 calls/ثانية للـREST، 1000/دقيقة للـGraphQL — راعها.
- ✅ **استخدم GraphQL Admin API** للعمليات المعقدة (أسرع وأقل rate-limited).
- ✅ **اربط Shopify webhooks → Salla/Zid** لو تبيع على عدة منصات (مزامنة المخزون).
