openapi: 3.1.0
info:
  title: NexNum Carrier Wire API
  description: |
    # NexNum Global SIM & SMS Wire Infrastructure
    Official carrier wire protocol gateway (`/stubs/handler_api.php`) for programmatic GSM SIM line allocation, dynamic OTP reception, and wallet reconciliation.

    ## 🔌 Universal Content Negotiation (JSON Junction)
    Responses default to standard telecom plain-text strings (`ACCESS_NUMBER:...`, `STATUS_OK:...`, `ACCESS_CANCEL`).
    Modern microservices and client bots can request structured JSON responses by either:
    - Appending query parameter `&format=json` or `&response_format=json`
    - Sending HTTP request header `Accept: application/json`

    ## 🔐 Authentication
    Authentication is passed via the query parameter `api_key=nx_live_...` or HTTP header `X-API-Key: nx_live_...`.
  version: 2.1.0-wire
  contact:
    name: NexNum Developer Support
    email: support@nexnum.in
    url: https://nexnum.in/en/api-docs

servers:
  - url: https://nexnum.in
    description: Production Carrier Wire Gateway
  - url: http://localhost:3000
    description: Local Development Gateway

paths:
  /stubs/handler_api.php:
    get:
      summary: Execute Carrier Wire Action
      description: |
        Primary carrier wire endpoint supporting all virtual line provisioning and SMS verification actions.
      operationId: executeWireAction
      parameters:
        - name: api_key
          in: query
          required: true
          description: Your NexNum API secret key (e.g. nx_live_...)
          schema:
            type: string
        - name: action
          in: query
          required: true
          description: Carrier action to perform
          schema:
            type: string
            enum:
              - getBalance
              - getNumber
              - getStatus
              - setStatus
              - getPrices
              - getServicesList
              - getCountriesList
              - getOperatorsList
              - getNumbersStatus
        - name: service
          in: query
          required: false
          description: Service code (e.g. wa for WhatsApp, tg for Telegram, go for Google)
          schema:
            type: string
        - name: country
          in: query
          required: false
          description: Country identifier (e.g. 22 for India, 0 for Russia, 187 for USA)
          schema:
            type: string
        - name: id
          in: query
          required: false
          description: Activation ID returned from getNumber (required for getStatus, setStatus)
          schema:
            type: string
        - name: status
          in: query
          required: false
          description: Lifecycle transition status for setStatus (1=Ready, 3=Retry, 6=Complete, 8=Cancel & Refund)
          schema:
            type: integer
            enum: [1, 3, 6, 8]
        - name: maxPrice
          in: query
          required: false
          description: Maximum allowable point cost for getNumber
          schema:
            type: number
        - name: operator
          in: query
          required: false
          description: Preferred GSM carrier network (e.g. jio, airtel, any)
          schema:
            type: string
        - name: format
          in: query
          required: false
          description: Response format override. Set to 'json' to receive structured JSON objects.
          schema:
            type: string
            enum: [json, text]
        - name: response_format
          in: query
          required: false
          description: Alternative alias for format parameter. Set to 'json' to receive structured JSON objects.
          schema:
            type: string
            enum: [json, text]
      responses:
        '200':
          description: Successful execution or standard telecom status response
          content:
            text/plain:
              schema:
                type: string
                examples:
                  getNumberSuccess:
                    value: "ACCESS_NUMBER:98472910:+919876543210"
                  getStatusWaiting:
                    value: "STATUS_WAIT_CODE"
                  getStatusReceived:
                    value: "STATUS_OK:394102"
                  setStatusCancel:
                    value: "ACCESS_CANCEL"
                  getBalanceSuccess:
                    value: "ACCESS_BALANCE:150.00"
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/JsonNumberSuccess'
                  - $ref: '#/components/schemas/JsonStatusSuccess'
                  - $ref: '#/components/schemas/JsonCancelSuccess'
                  - $ref: '#/components/schemas/JsonBalanceSuccess'
                  - $ref: '#/components/schemas/JsonPricesSuccess'
                  - $ref: '#/components/schemas/JsonProvidersList'
                  - $ref: '#/components/schemas/JsonErrorResponse'
        '401':
          description: Missing API Key
          content:
            text/plain:
              schema:
                type: string
                example: "NO_KEY"
            application/json:
              schema:
                $ref: '#/components/schemas/JsonErrorResponse'
        '403':
          description: Invalid or revoked API Key
          content:
            text/plain:
              schema:
                type: string
                example: "BAD_KEY"
            application/json:
              schema:
                $ref: '#/components/schemas/JsonErrorResponse'

components:
  schemas:
    JsonProvidersList:
      type: object
      required: [providers]
      properties:
        providers:
          type: array
          items:
            type: object
            required: [id, name]
            properties:
              id:
                type: string
                example: "9779"
              name:
                type: string
                example: NexGlobal
          example:
            - id: "9779"
              name: NexGlobal
            - id: "4591"
              name: NexSms
            - id: "6819"
              name: NexRush

    JsonNumberSuccess:
      type: object
      properties:
        status:
          type: string
          example: success
        activationId:
          type: string
          example: "98472910"
        phoneNumber:
          type: string
          example: "+919876543210"
        country:
          type: string
          example: "22"
        service:
          type: string
          example: "wa"
        cost:
          type: number
          example: 12.50

    JsonStatusSuccess:
      type: object
      properties:
        status:
          type: string
          example: "STATUS_OK"
        code:
          type: string
          nullable: true
          example: "394102"
        activationId:
          type: string
          example: "98472910"
        phoneNumber:
          type: string
          example: "+919876543210"
        fullSms:
          type: string
          nullable: true
          example: "Your verification code is 394102"
        sender:
          type: string
          nullable: true
          example: "WhatsApp"
        sms:
          type: array
          items:
            type: object
            properties:
              code:
                type: string
                example: "394102"
              text:
                type: string
                example: "Your verification code is 394102"
              receivedAt:
                type: string
                format: date-time
                example: "2026-09-19T16:45:00.000Z"

    JsonCancelSuccess:
      type: object
      properties:
        status:
          type: string
          example: success
        message:
          type: string
          example: "ACCESS_CANCEL"
        activationId:
          type: string
          example: "98472910"

    JsonBalanceSuccess:
      type: object
      properties:
        status:
          type: string
          example: success
        balance:
          type: number
          example: 150.00
        currency:
          type: string
          example: "POINTS"
        display:
          type: string
          example: "150.00 Points"

    JsonPricesSuccess:
      type: object
      additionalProperties:
        type: object
        additionalProperties:
          type: object
          properties:
            cost:
              type: number
              example: 12.50
            count:
              type: integer
              example: 1420

    JsonErrorResponse:
      type: object
      properties:
        status:
          type: string
          example: error
        code:
          type: string
          example: NO_NUMBERS
        message:
          type: string
          example: No available carrier lines for the requested service and country
