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

# إنشاء نطاق

> إنشاء نطاق إذن مخصص على مستوى المستأجر للتحكم الدقيق في وصول الوكيل

# إنشاء نطاق

`POST /v1/scopes`

ينشئ نطاق إذن مخصص للمستأجر المصادق عليه. توسع النطاقات المخصصة سجل النطاقات المدمج بأذونات خاصة بالمستأجر. يتم تكوين سلسلة النطاق تلقائيًا من حقلي `resource` و `action` بتنسيق `resource:action`.

يتم التحقق من النطاقات المخصصة مقابل قواعد تنسيق نطاق MAIP: أحرف أبجدية رقمية ونقاط وشرطات سفلية وواصلات وعلامات نجمية فقط.

> [!NOTE]
>
> النطاقات المخصصة معزولة للمستأجر. لا تظهر في نطاق المستأجرين الآخرين
> السجلات. لا يمكن تجاوز نطاقات النظام الأساسي المضمنة أو تكرارها.

### المصادقة

يتطلب رأس `X-API-Key` أو رمز Bearer JWT. يتم اشتقاق مساحة العمل من بيانات الاعتماد الموثقة؛ لا ترسل `X-Tenant-ID`.

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

**id** `string`

معرف UUID لتعريف النطاق الذي تم إنشاؤه حديثًا.

**tenant\_id** `string`

معرف UUID للمستأجر المالك.

**scope** `string`

سلسلة النطاق المركبة بتنسيق `resource:action`.

**resource** `string`

مكون المورد.

**action** `string`

مكون الإجراء.

**display\_name** `string`

اسم النطاق المقروء بشريًا.

**description** `string`

وصف النطاق.

**category** `string`

فئة النطاق.

**is\_builtin** `boolean`

دائمًا `false` للنطاقات التي أنشأها المستأجر.

**created\_at** `string`

طابع زمني لإنشاء ISO 8601.

### مثال

```bash theme={null}
curl -X POST https://api.truthlocks.com/v1/scopes \
  -H "X-API-Key: tl_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "resource": "crm",
    "action": "contact.enrich",
    "display_name": "CRM Contact Enrichment",
    "description": "Allows agents to enrich CRM contact records via third-party providers",
    "category": "integration"
  }'
```

***

### تعيين نطاقات مخصصة للوكلاء

بعد إنشاء نطاق مخصص، قم بتعيينه للوكلاء أثناء [التسجيل](https://docs.truthlocks.com/ar/api-reference/machine-identity/agents/register.md) أو عبر [التفويض](https://docs.truthlocks.com/ar/api-reference/machine-identity/agents/register.md):

```bash theme={null}
curl -X POST https://api.truthlocks.com/v1/agents \
  -H "X-API-Key: tl_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "agent_type": "pipeline",
    "display_name": "CRM Enrichment Pipeline",
    "scopes": ["crm:contact.enrich", "data:read"]
  }'
```


## OpenAPI

````yaml ar/mint-openapi.yaml POST /v1/scopes
openapi: 3.0.3
info:
  title: Truthlocks API
  description: >
    Truthlocks هي بنية تحتية عالمية للتحقق من المستندات وبيانات الاعتماد والأصول
    الرقمية.يحدد هذا المواصفات واجهة برمجة التطبيقات (API) الأساسية للتفاعل مع
    خدمات Truthlocks.


    ## عناوين URL الأساسية

    - **الإنتاج**: `https://api.truthlocks.com`

    - **البيئة التجريبية (Sandbox)**: `https://sandbox-api.truthlocks.com`


    ## المصادقة

    - **مفاتيح API**: استخدم رأس `X-API-Key` للعمليات من جهاز إلى جهاز

    - **رموز Bearer**: استخدم `Authorization: Bearer <jwt>` للعمليات التي يبدأها
    المستخدم


    ## هوية المستأجر

    في بيئة الإنتاج، تُستمد هوية المستأجر من السياق المصادق عليه (مفتاح API أو
    JWT).

    يتم تجاهل رأس `X-Tenant-ID` في بيئة الإنتاج لمنع الانتحال.
  version: 1.0.0
  contact:
    name: Truthlocks Support
    url: https://truthlocks.com/support
    email: support@truthlocks.com
servers:
  - url: https://api.truthlocks.com
    description: واجهة برمجة تطبيقات الإنتاج
  - url: https://sandbox-api.truthlocks.com
    description: بيئة اختبار (Sandbox)
security:
  - APIKey: []
  - BearerAuth: []
tags:
  - name: Authentication
    description: إدارة مفاتيح ورموز API
  - name: Issuers
    description: تسجيل المصدر وإدارة الثقة
  - name: Keys
    description: إدارة المفاتيح التشفيرية لجهات الإصدار
  - name: Attestations
    description: دورة حياة الإشهاد (السك، الإلغاء، الاستبدال)
  - name: Verification
    description: حزم التحقق والإثبات للإشهاد
  - name: Governance
    description: سير عمل حوكمة المصدر (للمسؤول فقط)
  - name: Identity
    description: إدارة المنظمة والمستخدمين والأدوار
  - name: Audit
    description: استعلامات أحداث التدقيق
  - name: Tenant Console
    description: ملف تعريف المستأجر ونقاط نهاية دورة الحياة
  - name: Health
    description: نقاط نهاية صحة الخدمة وجاهزيتها
  - name: Risk
    description: استيعاب إشارة المخاطر واكتشاف الاحتيال
  - name: Risk Enforcement
    description: إجراءات إنفاذ المخاطر — الحظر والتحدي والحجر والتكوين
  - name: Billing
    description: إدارة الفوترة والاشتراكات والإضافات
  - name: Machine Identity
    description: >-
      بروتوكول هوية وكيل الآلة (MAIP) — تسجيل الوكيل، الجلسات، الثقة، الشهادة،
      الامتثال، التنسيق، والمراقبة
externalDocs:
  description: واجهة برمجة تطبيقات الشفافية للقراءة فقط (مواصفات خدمة منفصلة)
  url: >-
    https://github.com/truthlocks/truthlock/blob/main/docs/transparency/openapi.yaml
paths:
  /v1/scopes:
    post:
      tags:
        - Machine Identity
      summary: إنشاء نطاق
      description: ينشئ نطاق إذن مخصص على مستوى المستأجر للتحكم الدقيق في وصول الوكيل.
      operationId: maip.scopes.create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              properties:
                action:
                  type: string
                  description: مكون الإجراء للنطاق (مثل "قراءة"، "موافقة"، "*")
                category:
                  type: string
                  description: الفئة التنظيمية (الافتراضي هو "مخصص")
                description:
                  type: string
                  description: وصف تفصيلي لما يمنحه النطاق
                display_name:
                  type: string
                  description: اسم مقروء بشريًا للنطاق
                resource:
                  type: string
                  description: مكون المورد للنطاق (مثل "crm"، "payment")
              type: object
              required:
                - resource
                - action
      responses:
        '201':
          description: تم إنشاء النطاق
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                  tenant_id:
                    type: string
                    format: uuid
                  scope:
                    type: string
                  resource:
                    type: string
                  action:
                    type: string
                  display_name:
                    type: string
                  description:
                    type: string
                  category:
                    type: string
                  is_builtin:
                    type: boolean
                  created_at:
                    type: string
                    format: date-time
        '400':
          description: خطأ في التحقق
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '401':
          description: المصادقة مطلوبة
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '409':
          description: النطاق موجود بالفعل
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '429':
          description: تجاوز حد المعدل
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
      security:
        - APIKey: []
components:
  schemas:
    ErrorEnvelope:
      type: object
      required:
        - code
        - message
        - http_status
      properties:
        code:
          type: string
          description: رمز خطأ قابل للقراءة آليًا
          enum:
            - AUTH_REQUIRED
            - AUTH_INVALID
            - PERMISSION_DENIED
            - TENANT_IDENTITY_UNVERIFIED
            - NOT_FOUND
            - VALIDATION_ERROR
            - CONFLICT
            - PAYLOAD_TOO_LARGE
            - RATE_LIMIT_EXCEEDED
            - QUOTA_EXCEEDED
            - SERVICE_UNAVAILABLE
            - INTERNAL_ERROR
        message:
          type: string
          description: رسالة خطأ مقروءة بشريًا
        http_status:
          type: integer
          description: رمز حالة HTTP
        retry_after_ms:
          type: integer
          description: عدد المللي ثانية للانتظار قبل إعادة المحاولة (لحدود المعدل)
        details:
          type: object
          description: سياق خطأ إضافي
      example:
        code: AUTH_REQUIRED
        message: Authentication required
        http_status: 401
  securitySchemes:
    APIKey:
      type: apiKey
      in: header
      name: X-API-Key
      description: مفتاح API للمصادقة من جهاز إلى جهاز
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT للعمليات التي يبدأها المستخدم

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.