openapi: 3.1.0
info:
  title: Botswana National KYC Hub — Partner API
  version: 1.0.0
  x-logo:
    url: /brand/logo.png
    altText: Botswana National KYC Hub
    href: /
  description: |
    For institutions' own systems (core banking, loan origination, SIM
    registration). Customers verify once in the Hub; under the consent they
    gave at onboarding, registered institutions retrieve the verified record.
    Customers see every retrieval in their app and can block an institution;
    a blocked institution receives `unavailable` and is never told why.

    **Authentication.** Create a secret key in the portal (API & integration).
    Send it on every request: `Authorization: Bearer hub_<env>_sk_...`. Keys
    are shown once; keep them on your servers only, never in apps or browsers.
    Revoke a key in the portal if it may have leaked.

    **Idempotency.** Send an `Idempotency-Key` header (e.g. a UUID) on POST
    requests. Retries with the same key within 24 hours return the original
    response and are not billed twice.

    **Limits.** Requests per key per minute are limited (shown in the portal).
    Over the limit you receive 429 with `Retry-After`.

    **Billing.** Each successful `retrieve` is billed. Lookups and invites are
    free.

    **Branches.** Send `branchCode` (e.g. `GC01`, as set up in the portal
    under Branches) to say which branch a call is for. The call is then
    logged and billed to that branch, and the customer sees the branch name
    in their access history. Without it, the call counts for head office.
servers:
  - url: https://africa-south1-bw-kyc-hub-dev.cloudfunctions.net/api/v1
    description: Test server (test data only)
security:
  - apiKey: []
paths:
  /partner/me:
    get:
      summary: Check your key
      responses:
        '200':
          description: The institution the key belongs to.
          content:
            application/json:
              schema:
                type: object
                required: [institution, environment]
                properties:
                  institution:
                    type: object
                    required: [id, name]
                    properties:
                      id: { type: string }
                      name: { type: string }
                  environment: { type: string, enum: [dev, production] }
        '401': { $ref: '#/components/responses/Problem' }
        '403': { $ref: '#/components/responses/Problem' }
        '429': { $ref: '#/components/responses/Problem' }
  /partner/records/lookup:
    post:
      summary: Does a verified record exist?
      description: Reveals only whether a verified record exists. Free.
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [idNumber]
              properties:
                idNumber: { type: string, description: 9-digit Omang number, example: '123412345' }
                branchCode: { $ref: '#/components/schemas/BranchCode' }
      responses:
        '200':
          description: Result.
          content:
            application/json:
              schema:
                type: object
                required: [found]
                properties:
                  found: { type: boolean }
        '422': { $ref: '#/components/responses/Problem' }
        '401': { $ref: '#/components/responses/Problem' }
        '429': { $ref: '#/components/responses/Problem' }
  /partner/records/retrieve:
    post:
      summary: Retrieve the verified record (billed)
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [idNumber, purpose]
              properties:
                idNumber: { type: string, example: '123412345' }
                purpose:
                  type: string
                  maxLength: 200
                  description: Why you need the record. Recorded for audit.
                  example: Opening a savings account
                branchCode: { $ref: '#/components/schemas/BranchCode' }
      responses:
        '200':
          description: The record, or `unavailable` if the customer blocked your institution.
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    required: [status]
                    properties:
                      status: { const: unavailable }
                  - $ref: '#/components/schemas/Retrieved'
        '404':
          description: No verified record. Send the customer an invite instead.
          content:
            application/problem+json:
              schema: { $ref: '#/components/schemas/Problem' }
        '401': { $ref: '#/components/responses/Problem' }
        '422': { $ref: '#/components/responses/Problem' }
        '429': { $ref: '#/components/responses/Problem' }
  /partner/invites:
    post:
      summary: Invite a customer who is not in the Hub yet
      description: |
        Returns a code valid for 14 days. The customer enters it in the Hub
        app (or opens https://kycsasa.com/invite/CODE); once
        verified, your institution can retrieve the record. Until an SMS
        provider is connected, pass the code to the customer yourself
        (`smsSent: false`).
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [phoneNumber]
              properties:
                phoneNumber: { type: string, example: '+26771234567' }
                branchCode: { $ref: '#/components/schemas/BranchCode' }
      responses:
        '201':
          description: Invite created.
          content:
            application/json:
              schema:
                type: object
                required: [code, expiresAt, smsSent]
                properties:
                  code: { type: string, example: 7KQ2M9XA }
                  expiresAt: { type: string, format: date-time }
                  smsSent: { type: boolean }
        '401': { $ref: '#/components/responses/Problem' }
        '422': { $ref: '#/components/responses/Problem' }
        '429': { $ref: '#/components/responses/Problem' }
  /partner/businesses/lookup:
    post:
      summary: Does the Hub hold a verified business with this CIPA number?
      description: |
        Reveals only whether a verified business exists. A business is
        verified once its representative and every director and owner they
        listed have verified themselves in the Hub. Audited.
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [registrationNumber]
              properties:
                registrationNumber:
                  type: string
                  description: CIPA UIN, BW and 11 digits. Spaces are ignored.
                  example: BW00001234567
                branchCode: { $ref: '#/components/schemas/BranchCode' }
      responses:
        '200':
          description: Whether a verified business exists
          content:
            application/json:
              schema:
                type: object
                required: [found]
                properties:
                  found: { type: boolean }
        '401': { $ref: '#/components/responses/Problem' }
        '422': { $ref: '#/components/responses/Problem' }
        '429': { $ref: '#/components/responses/Problem' }
  /partner/businesses/retrieve:
    post:
      summary: Retrieve the verified business (billed)
      description: The representative sees every retrieval in their app.
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [registrationNumber, purpose]
              properties:
                registrationNumber: { type: string, example: BW00001234567 }
                purpose:
                  type: string
                  maxLength: 200
                  description: Why you need the record. Recorded for audit.
                  example: Business account opening
                branchCode: { $ref: '#/components/schemas/BranchCode' }
      responses:
        '200':
          description: The verified business
          content:
            application/json:
              schema: { $ref: '#/components/schemas/RetrievedBusiness' }
        '404':
          description: No verified business for that number.
          content:
            application/problem+json:
              schema: { $ref: '#/components/schemas/Problem' }
        '401': { $ref: '#/components/responses/Problem' }
        '422': { $ref: '#/components/responses/Problem' }
        '429': { $ref: '#/components/responses/Problem' }
components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: Secret key from the portal, `hub_<env>_sk_...`.
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema: { type: string, maxLength: 100 }
  responses:
    Problem:
      description: Error (RFC 9457 problem details).
      content:
        application/problem+json:
          schema: { $ref: '#/components/schemas/Problem' }
  schemas:
    BranchCode:
      type: string
      maxLength: 12
      description: Optional. Your branch's code from the portal (Branches). Unknown or closed codes are refused (422).
      example: GC01
    Problem:
      type: object
      required: [status, code, requestId]
      properties:
        status: { type: integer }
        code:
          type: string
          enum: [validation_failed, unauthorized, not_found, conflict, idempotency_conflict, rate_limited, server_error]
        requestId: { type: string, description: Quote this when contacting the Hub. }
        userMessage: { type: string }
        fieldErrors:
          type: array
          items:
            type: object
            required: [field, message]
            properties:
              field: { type: string }
              message: { type: string }
        retryAfterSeconds: { type: integer }
    Retrieved:
      type: object
      required: [status, record, charge]
      properties:
        status: { const: retrieved }
        record:
          type: object
          required: [fullName, checks]
          properties:
            fullName: { type: string }
            dateOfBirth: { type: [string, 'null'], format: date }
            address: { type: [string, 'null'] }
            idDocument:
              type: [object, 'null']
              properties:
                type: { type: string, example: Omang }
                number: { type: string }
                issuedOn: { type: string, format: date }
                expiresOn: { type: string, format: date }
                validity: { type: string, enum: [valid, expiring_soon, expired] }
                datesSource: { type: string }
            verifiedAt: { type: [string, 'null'], format: date-time }
            updatedAt: { type: [string, 'null'], format: date-time }
            checks:
              type: array
              items:
                type: object
                required: [id, label, status]
                properties:
                  id: { type: string, enum: [registry_lookup, document_authenticity, face_match, liveness] }
                  label: { type: string }
                  status: { type: string, enum: [passed] }
            credentials:
              type: array
              description: |
                Official documents a Hub reviewer checked (included in the
                price). Issuer registries are not connected yet.
              items: { $ref: '#/components/schemas/Credential' }
        charge:
          type: object
          required: [amountPula]
          properties:
            amountPula: { type: number }
    RetrievedBusiness:
      type: object
      required: [status, record, charge]
      properties:
        status: { const: retrieved }
        record:
          type: object
          required: [legalName, registrationNumber, people, checks]
          properties:
            legalName: { type: string }
            tradingName: { type: [string, 'null'] }
            registrationNumber: { type: string }
            businessType: { type: [string, 'null'], example: Private company }
            registeredOn: { type: [string, 'null'], format: date }
            natureOfBusiness: { type: [string, 'null'] }
            registeredAddress: { type: [string, 'null'] }
            verifiedAt: { type: [string, 'null'], format: date-time }
            people:
              type: array
              description: Representative, directors and owners. Names come from each person's own verified record.
              items:
                type: object
                required: [fullName, role, ownershipPercent, representative, verifiedInHub]
                properties:
                  fullName: { type: string }
                  role: { type: string, example: Director and owner }
                  ownershipPercent: { type: number, minimum: 0, maximum: 100 }
                  representative: { type: boolean }
                  verifiedInHub: { type: boolean }
            checks:
              type: array
              items:
                type: object
                required: [id, label, status]
                properties:
                  id: { type: string, enum: [business_registry, documents_received, people_verified] }
                  label: { type: string }
                  status: { type: string, enum: [passed] }
            credentials:
              type: array
              description: |
                Official documents a Hub reviewer checked (included in the
                price). Issuer registries are not connected yet.
              items: { $ref: '#/components/schemas/Credential' }
        charge:
          type: object
          required: [amountPula]
          properties:
            amountPula: { type: number }
    Credential:
      type: object
      required: [type, title, validity]
      properties:
        type:
          type: string
          enum: [drivers_licence, tax_clearance, trade_licence, vat_registration, ppra_registration, proof_of_place_of_work]
        title: { type: string }
        number: { type: [string, 'null'] }
        issuer: { type: string }
        licenceCode: { type: string }
        issuedOn: { type: [string, 'null'], format: date }
        expiresOn: { type: [string, 'null'], format: date }
        validity: { type: string, enum: [valid, expiring_soon, expired] }
        checkedOn: { type: [string, 'null'], format: date-time }
        checkedBy: { type: string }
