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

# الحصول على كتالوج المنتجات

> احصل على جميع بطاقات الهدايا والمنتجات الرقمية المتاحة مجمَّعة حسب الفئة

<div dir="rtl">
  ## نظرة عامة

  يعيد الكتالوج الكامل لبطاقات الهدايا والمنتجات الرقمية المنظَّمة حسب الفئات (الألعاب، البث، إلخ).

  <Tip>
    **احتفظ بهذه البيانات في cache** لمدة 24 ساعة على الأقل. يتغير الكتالوج نادراً.
  </Tip>

  ## الاستجابة

  <ResponseField name="success" type="boolean" required>
    حالة الطلب
  </ResponseField>

  <ResponseField name="totalCategories" type="integer">
    إجمالي عدد الفئات في الكتالوج
  </ResponseField>

  <ResponseField name="totalProducts" type="integer">
    إجمالي عدد المنتجات عبر جميع الفئات
  </ResponseField>

  <ResponseField name="data" type="object" required>
    <Expandable title="الخصائص">
      <ResponseField name="categories" type="array">
        مصفوفة كائنات الفئات مع المنتجات

        <Expandable title="كائن الفئة">
          <ResponseField name="title" type="string">
            اسم الفئة (مثال: "PSN"، "Game Stores"، "iTunes")
          </ResponseField>

          <ResponseField name="products" type="array">
            مصفوفة كائنات المنتجات

            <Expandable title="كائن المنتج">
              <ResponseField name="id" type="string">
                معرف المنتج الفريد (للاستخدام مع `/check-product`)
              </ResponseField>

              <ResponseField name="title" type="string">
                اسم عرض المنتج
              </ResponseField>

              <ResponseField name="enabled" type="boolean">
                متاح عبر API
              </ResponseField>

              <ResponseField name="region" type="string">
                كود المنطقة الجغرافية (مثال: "germany"، "united-states-america")
              </ResponseField>
            </Expandable>
          </ResponseField>
        </Expandable>
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="meta" type="object">
    <Expandable title="الخصائص">
      <ResponseField name="timestamp" type="string">
        طابع زمني للاستجابة بتنسيق ISO 8601
      </ResponseField>
    </Expandable>
  </ResponseField>

  ## أمثلة

  <CodeGroup>
    ```bash cURL theme={null}
    curl https://api.oneclickdz.com/v3/gift-cards/catalog \
      -H "X-Access-Token: YOUR_API_KEY"
    ```

    ```javascript Node.js theme={null}
    const response = await fetch(
      "https://api.oneclickdz.com/v3/gift-cards/catalog",
      {
        headers: { "X-Access-Token": "YOUR_API_KEY" },
      }
    );
    const { data } = await response.json();

    // Filter enabled products
    const enabledProducts = data.categories.flatMap((cat) =>
      cat.products.filter((p) => p.enabled)
    );
    ```

    ```python Python theme={null}
    response = requests.get(
        'https://api.oneclickdz.com/v3/gift-cards/catalog',
        headers={'X-Access-Token': 'YOUR_API_KEY'}
    )
    catalog = response.json()['data']

    # Filter by category
    gaming = next(c for c in catalog['categories'] if c['name'] == 'Gaming Cards')
    ```

    ```php PHP theme={null}
    <?php
    $ch = curl_init('https://api.oneclickdz.com/v3/gift-cards/catalog');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Access-Token: YOUR_API_KEY']);
    $response = json_decode(curl_exec($ch), true);
    $categories = $response['data']['categories'];
    ?>
    ```
  </CodeGroup>

  ### مثال الاستجابة

  ```json theme={null}
  {
    "success": true,
    "totalCategories": 14,
    "totalProducts": 62,
    "data": {
      "categories": [
        {
          "title": "PSN",
          "products": [
            {
              "id": "6126393c6f57860f925a1983",
              "title": "PSN Germany",
              "enabled": true,
              "region": "germany"
            },
            {
              "id": "612619816f57860f9259eee3",
              "title": "PSN UK",
              "enabled": true,
              "region": "united-kingdom"
            }
          ]
        }
      ]
    },
    "meta": {
      "timestamp": "2025-10-29T00:36:52.615Z"
    }
  }
  ```

  ## بناء واجهة عرض المنتجات

  ```javascript theme={null}
  // Example: Building a category-based UI
  function renderCatalog(catalog) {
    return catalog.categories.map((category) => ({
      categoryName: category.name,
      products: category.products
        .filter((p) => p.enabled)
        .map((p) => ({
          id: p.id,
          name: p.title,
          imageUrl: `/images/products/${p.id}.png`,
        })),
    }));
  }
  ```

  ## استراتيجية التخزين المؤقت

  <CodeGroup>
    ```javascript Node.js theme={null}
    // Cache for 24 hours
    const cache = {
      data: null,
      timestamp: 0,
      ttl: 24 * 60 * 60 * 1000, // 24 hours
    };

    async function getCatalog() {
      const now = Date.now();

      if (cache.data && now - cache.timestamp < cache.ttl) {
        return cache.data;
      }

      const response = await fetch(
        "https://api.oneclickdz.com/v3/gift-cards/catalog",
        {
          headers: { "X-Access-Token": process.env.API_KEY },
        }
      );

      cache.data = await response.json();
      cache.timestamp = now;

      return cache.data;
    }
    ```

    ```python Python theme={null}
    from datetime import datetime, timedelta
    import requests

    class CatalogCache:
        def __init__(self):
            self.data = None
            self.timestamp = None
            self.ttl = timedelta(minutes=10)

        def get(self):
            if self.data and datetime.now() - self.timestamp < self.ttl:
                return self.data

            response = requests.get(
                'https://api.oneclickdz.com/v3/gift-cards/catalog',
                headers={'X-Access-Token': 'YOUR_API_KEY'}
            )

            self.data = response.json()
            self.timestamp = datetime.now()

            return self.data

    catalog_cache = CatalogCache()
    ```
  </CodeGroup>

  ## أفضل الممارسات

  <CardGroup cols={2}>
    <Card title="التخزين المؤقت للكتالوج" icon="database">
      خزّن لمدة 10 دقائق أو أكثر لتقليل استدعاءات API
    </Card>

    <Card title="تصفية المُفعَّل" icon="filter">
      أظهر فقط المنتجات حيث `enabled: true`
    </Card>

    <Card title="التحقق من المنطقة" icon="earth-americas">
      فلترة حسب المنطقة إذا كنت تستهدف أسواقاً محددة
    </Card>

    <Card title="التنظيم حسب الفئة" icon="folder-tree">
      استخدم الفئات لتجربة مستخدم أفضل
    </Card>
  </CardGroup>

  ## الخطوات التالية

  بعد الحصول على الكتالوج:

  <Steps>
    <Step title="عرض المنتجات">
      أظهر المنتجات للمستخدمين منظمةً حسب الفئة
    </Step>

    <Step title="التحقق من تفاصيل المنتج">
      استخدم `/checkProduct/:id` للحصول على الأسعار والمخزون
    </Step>

    <Step title="تقديم الطلب">
      استخدم `/placeOrder` لشراء المنتج المحدد
    </Step>
  </Steps>

  ## ذات صلة

  <CardGroup cols={2}>
    <Card title="التحقق من المنتج" icon="magnifying-glass" href="/ar/api-reference/gift-cards/check-product">
      الحصول على الأسعار والمخزون
    </Card>

    <Card title="تقديم طلب" icon="cart-shopping" href="/ar/api-reference/gift-cards/place-order">
      شراء المنتج
    </Card>
  </CardGroup>
</div>
