{
  "openapi": "3.0.3",
  "info": {
    "title": "A8 QR Scan API",
    "version": "2.0",
    "description": "Server-to-server API. Access keys are issued separately. Never use legacy v1 as a fallback. Examples use synthetic identifiers. Contract reviewed against provider source on 2026-10-22."
  },
  "servers": [
    {
      "url": "https://a8pro.kz/qrscan/api/v2"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/sessions": {
      "post": {
        "operationId": "createSession",
        "description": "Create or retrieve a session by request_id and context. Initial TTL 10 minutes. Expired sessions are not restarted.",
        "parameters": [
          {
            "name": "Accept",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "application/json"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateSession"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful operation; inspect status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid Bearer key."
          },
          "403": {
            "description": "Organization is inactive."
          },
          "404": {
            "description": "Session missing or does not belong to this context."
          },
          "409": {
            "description": "Context or receipt mismatch."
          },
          "422": {
            "description": "Validation failed; inspect errors."
          },
          "429": {
            "description": "Rate limit exceeded; respect Retry-After."
          },
          "500": {
            "description": "Server error; retry with backoff."
          }
        }
      }
    },
    "/sessions/{requestId}/result": {
      "post": {
        "operationId": "receiveResult",
        "description": "Poll with receive=false. After operator confirmation receive=true returns data and receipt_token; first receive sets a 30-minute expiry. Retries before ACK return the same result.",
        "parameters": [
          {
            "name": "Accept",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "application/json"
              ]
            }
          },
          {
            "name": "requestId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResultRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful operation; inspect status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Result"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid Bearer key."
          },
          "403": {
            "description": "Organization is inactive."
          },
          "404": {
            "description": "Session missing or does not belong to this context."
          },
          "409": {
            "description": "Context or receipt mismatch."
          },
          "422": {
            "description": "Validation failed; inspect errors."
          },
          "429": {
            "description": "Rate limit exceeded; respect Retry-After."
          },
          "500": {
            "description": "Server error; retry with backoff."
          }
        }
      }
    },
    "/sessions/{requestId}/ack": {
      "post": {
        "operationId": "acknowledgeResult",
        "description": "Durably save the result first. ACK clears server result data and is repeatable with the same receipt.",
        "parameters": [
          {
            "name": "Accept",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "application/json"
              ]
            }
          },
          {
            "name": "requestId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AckRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful operation; inspect status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Acknowledgement"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid Bearer key."
          },
          "403": {
            "description": "Organization is inactive."
          },
          "404": {
            "description": "Session missing or does not belong to this context."
          },
          "409": {
            "description": "Context or receipt mismatch."
          },
          "422": {
            "description": "Validation failed; inspect errors."
          },
          "429": {
            "description": "Rate limit exceeded; respect Retry-After."
          },
          "500": {
            "description": "Server error; retry with backoff."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Organization API key. Keep on the integration server."
      }
    },
    "schemas": {
      "CreateSession": {
        "type": "object",
        "required": [
          "request_id",
          "exchange_point_id",
          "node_id"
        ],
        "properties": {
          "exchange_point_id": {
            "type": "string",
            "format": "uuid",
            "description": "Stable service point UUID agreed during integration."
          },
          "node_id": {
            "type": "string",
            "format": "uuid",
            "description": "Stable workstation UUID."
          },
          "request_id": {
            "type": "string",
            "format": "uuid",
            "description": "Idempotency identifier. Reuse for retries, change for a new document."
          },
          "photo_quality": {
            "type": "string",
            "enum": [
              "high",
              "medium",
              "low"
            ],
            "default": "medium"
          },
          "scan_mode": {
            "type": "string",
            "enum": [
              "auto",
              "digital",
              "plastic",
              "passport"
            ],
            "default": "digital"
          }
        }
      },
      "Session": {
        "type": "object",
        "required": [
          "request_id",
          "status",
          "mobile_url",
          "expires_at"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string"
          },
          "mobile_url": {
            "type": "string",
            "format": "uri",
            "description": "Temporary HTTPS URL to display as a QR code."
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ResultRequest": {
        "type": "object",
        "required": [
          "exchange_point_id",
          "node_id"
        ],
        "properties": {
          "exchange_point_id": {
            "type": "string",
            "format": "uuid",
            "description": "Stable service point UUID agreed during integration."
          },
          "node_id": {
            "type": "string",
            "format": "uuid",
            "description": "Stable workstation UUID."
          },
          "receive": {
            "type": "boolean",
            "default": false,
            "description": "false polls without freezing capture; true receives and freezes the completed result."
          }
        }
      },
      "Result": {
        "type": "object",
        "required": [
          "status"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "waiting",
              "ready",
              "sent",
              "expired",
              "error"
            ]
          },
          "receipt_token": {
            "type": "string",
            "minLength": 64,
            "maxLength": 64,
            "description": "Returned with data after receive=true. Save before ACK."
          },
          "data": {
            "type": "object",
            "additionalProperties": true,
            "properties": {
              "document_name": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              },
              "iin": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              },
              "last_name": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              },
              "first_name": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              },
              "middle_name": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              },
              "birth_date": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              },
              "document_number": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              },
              "place_of_birth": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              },
              "nationality": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              },
              "issuing_authority": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              },
              "issue_date": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              },
              "expiry_date": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              },
              "citizenship": {
                "type": "string",
                "description": "May be empty or absent. Validate before use."
              }
            }
          }
        }
      },
      "AckRequest": {
        "type": "object",
        "required": [
          "exchange_point_id",
          "node_id",
          "receipt_token"
        ],
        "properties": {
          "exchange_point_id": {
            "type": "string",
            "format": "uuid",
            "description": "Stable service point UUID agreed during integration."
          },
          "node_id": {
            "type": "string",
            "format": "uuid",
            "description": "Stable workstation UUID."
          },
          "receipt_token": {
            "type": "string",
            "minLength": 64,
            "maxLength": 64
          }
        }
      },
      "Acknowledgement": {
        "type": "object",
        "required": [
          "status"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "sent"
            ]
          }
        }
      }
    }
  }
}

