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

# Toggle integration active state

> Mirrors the merchant's external-platform toggle (Matajer's "ربط بوينتس"
switch today, any other channel tomorrow) into our DB. Flips the
`integration_active` flag on the API key that authenticated the
request — driving the green/red dot on our `/merchants` listing and
any business logic that needs to know "is this merchant currently
toggled on?"

Distinct from `Key.status`, which is the auth-validity flag (admin
can kill a leaked key without touching the merchant's intent). The
two flags compose: a merchant is shown as **active** only when
both are `true`.

Idempotent — sending `{ "active": true }` on an already-active key
(or vice-versa) is a no-op that still returns `200`. Safe to retry.




## OpenAPI

````yaml /openapi/points-api-v1.yaml post /v1/integration/status
openapi: 3.0.3
info:
  title: Points API
  version: 1.0.0
  description: >
    OpenAPI definition for the `/api/v1` endpoints defined in
    `routes/api_v1.php`. This spec reflects the behaviour of the Laravel backend
    and is the source of truth for integrators.
  contact:
    name: Points API Support
    email: support@papp.sa
    url: https://docs.papp.sa
servers:
  - url: https://business.papp.sa/api
    description: Production server
  - url: https://sandbox.papp.sa/api
    description: Sandbox server
security:
  - ApiKeyAuth: []
tags:
  - name: Orders
    description: Operations for creating and managing orders
  - name: Webhooks
    description: CRUD operations for merchant webhooks
  - name: Integration
    description: External-platform toggle state (e.g. Matajer's "ربط بوينتس" switch)
paths:
  /v1/integration/status:
    post:
      tags:
        - Integration
      summary: Toggle integration active state
      description: |
        Mirrors the merchant's external-platform toggle (Matajer's "ربط بوينتس"
        switch today, any other channel tomorrow) into our DB. Flips the
        `integration_active` flag on the API key that authenticated the
        request — driving the green/red dot on our `/merchants` listing and
        any business logic that needs to know "is this merchant currently
        toggled on?"

        Distinct from `Key.status`, which is the auth-validity flag (admin
        can kill a leaked key without touching the merchant's intent). The
        two flags compose: a merchant is shown as **active** only when
        both are `true`.

        Idempotent — sending `{ "active": true }` on an already-active key
        (or vice-versa) is a no-op that still returns `200`. Safe to retry.
      operationId: setIntegrationStatus
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IntegrationStatusRequest'
            examples:
              enable:
                summary: Merchant toggled the integration ON
                value:
                  active: true
              disable:
                summary: Merchant toggled the integration OFF
                value:
                  active: false
      responses:
        '200':
          description: Status accepted (idempotent — current state shown in `data.active`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IntegrationStatusResponse'
        '400':
          $ref: '#/components/responses/Unauthorized'
        '422':
          $ref: '#/components/responses/ValidationError'
        '429':
          description: Too many toggle calls — endpoint is rate-limited to 30/min per key.
components:
  schemas:
    IntegrationStatusRequest:
      type: object
      required:
        - active
      properties:
        active:
          type: boolean
          description: |
            `true` when the merchant just toggled the integration ON in the
            external platform (Matajer's "ربط بوينتس" switch today),
            `false` on toggle OFF.
          example: true
    IntegrationStatusResponse:
      type: object
      required:
        - status
        - message
        - data
      properties:
        data:
          type: object
          required:
            - active
          properties:
            active:
              type: boolean
              description: >-
                The resolved `integration_active` flag after this call (matches
                the request body in success cases).
              example: true
        status:
          type: boolean
          example: true
        message:
          type: string
          example: Integration status updated
        appended_data:
          type: array
          items: {}
          example: []
    ErrorResponse:
      type: object
      required:
        - status
        - message
        - appended_data
      properties:
        status:
          type: boolean
          example: false
        message:
          type: string
          example: Invalid or inactive API key
        appended_data:
          type: object
          additionalProperties: true
          example: {}
    ValidationErrorResponse:
      type: object
      required:
        - status
        - message
        - appended_data
      properties:
        status:
          type: boolean
          example: false
        message:
          type: string
          example: The given data was invalid.
        appended_data:
          type: object
          additionalProperties: true
          example: {}
        errors:
          type: object
          description: >
            Field-level validation errors. Keys are field names (dot-notation
            for nested fields, e.g. `products.0.product_price`). Values are
            arrays of error message strings.
          additionalProperties:
            type: array
            items:
              type: string
          example:
            total_price:
              - The total price field is required.
            products.0.quantity:
              - The quantity must be at least 1.
  responses:
    Unauthorized:
      description: >
        The `x-api-key` header is missing, invalid, or belongs to an inactive
        merchant. The Points API returns `400` (not `401`) for auth failures.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    ValidationError:
      description: Request body failed validation.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValidationErrorResponse'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````