{
  "openapi": "3.1.0",
  "info": {
    "title": "ChiruSMS REST API",
    "version": "1.1.0",
    "description": "Amounts are USD. Requests use account balance. A pending purchase must be polled, not repurchased. channelId is optional and defaults to channel-1. Query /api/v1/channels for available channel IDs. No-code refunds occur after cancellation is confirmed."
  },
  "servers": [
    {
      "url": "https://chirusms.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Order": {
        "type": "object",
        "required": [
          "id",
          "ref",
          "channelId",
          "service",
          "country",
          "price",
          "status",
          "codes"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "ref": {
            "type": "string"
          },
          "channelId": {
            "type": "string"
          },
          "service": {
            "type": "string"
          },
          "country": {
            "type": "integer"
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "price": {
            "type": "number"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "waiting",
              "received",
              "completed",
              "cancelled",
              "expired",
              "failed"
            ]
          },
          "codes": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "text": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "receivedAt": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "canResend": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "numberReceivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "cancelableAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "numberRequest": {
            "type": "object",
            "description": "Present while a number is being allocated or an uncertain allocation is verified. Poll this order; do not purchase again.",
            "properties": {
              "state": {
                "type": "string",
                "enum": [
                  "searching",
                  "verifying"
                ]
              },
              "deadlineAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time",
                "description": "Search deadline; null while an uncertain purchase is being verified."
              }
            },
            "required": [
              "state",
              "deadlineAt"
            ]
          },
          "cancellationReason": {
            "description": "Historical feedback, when available.",
            "deprecated": true,
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "wait_too_long",
              "app_not_sent",
              "number_rejected",
              "wrong_purchase",
              "other",
              null
            ]
          },
          "cancellationNote": {
            "description": "Historical feedback, when available.",
            "deprecated": true,
            "type": [
              "string",
              "null"
            ],
            "maxLength": 300
          },
          "firstSmsRecordedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "repeatedNumber": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "properties": {
                  "previousUnsuccessfulUses": {
                    "type": "integer"
                  },
                  "lastUsedAt": {
                    "type": "string",
                    "format": "date-time"
                  }
                },
                "required": [
                  "previousUnsuccessfulUses",
                  "lastUsedAt"
                ]
              }
            ],
            "description": "Previous refunded no-code uses of the same number by this account for the same app and country within 24 hours before this order. Informational; does not change the order or its price."
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "data": {
            "type": "object"
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/balance": {
      "get": {
        "summary": "Get account balance",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "balance": {
                      "type": "number"
                    },
                    "currency": {
                      "const": "USD"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "INVALID_INPUT"
          },
          "401": {
            "description": "BAD_KEY"
          },
          "409": {
            "description": "Business conflict, including PRICE_CHANGED, IDEMPOTENCY_CONFLICT, NO_NUMBERS, CHANNEL_UNAVAILABLE or CANCEL_TOO_EARLY"
          },
          "429": {
            "description": "RATE_LIMITED; data.retryAfter is seconds"
          },
          "503": {
            "description": "TEMPORARILY_UNAVAILABLE"
          }
        }
      }
    },
    "/api/v1/services": {
      "get": {
        "summary": "List available apps",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "INVALID_INPUT"
          },
          "401": {
            "description": "BAD_KEY"
          },
          "409": {
            "description": "Business conflict, including PRICE_CHANGED, IDEMPOTENCY_CONFLICT, NO_NUMBERS, CHANNEL_UNAVAILABLE or CANCEL_TOO_EARLY"
          },
          "429": {
            "description": "RATE_LIMITED; data.retryAfter is seconds"
          },
          "503": {
            "description": "TEMPORARILY_UNAVAILABLE"
          }
        }
      }
    },
    "/api/v1/countries": {
      "get": {
        "summary": "List canonical country IDs",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "INVALID_INPUT"
          },
          "401": {
            "description": "BAD_KEY"
          },
          "409": {
            "description": "Business conflict, including PRICE_CHANGED, IDEMPOTENCY_CONFLICT, NO_NUMBERS, CHANNEL_UNAVAILABLE or CANCEL_TOO_EARLY"
          },
          "429": {
            "description": "RATE_LIMITED; data.retryAfter is seconds"
          },
          "503": {
            "description": "TEMPORARILY_UNAVAILABLE"
          }
        }
      }
    },
    "/api/v1/channels": {
      "get": {
        "summary": "List public supplier channels",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "channels": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "INVALID_INPUT"
          },
          "401": {
            "description": "BAD_KEY"
          },
          "409": {
            "description": "Business conflict, including PRICE_CHANGED, IDEMPOTENCY_CONFLICT, NO_NUMBERS, CHANNEL_UNAVAILABLE or CANCEL_TOO_EARLY"
          },
          "429": {
            "description": "RATE_LIMITED; data.retryAfter is seconds"
          },
          "503": {
            "description": "TEMPORARILY_UNAVAILABLE"
          }
        }
      }
    },
    "/api/v1/prices": {
      "get": {
        "summary": "List current per-country selling prices",
        "parameters": [
          {
            "name": "service",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "INVALID_INPUT"
          },
          "401": {
            "description": "BAD_KEY"
          },
          "409": {
            "description": "Business conflict, including PRICE_CHANGED, IDEMPOTENCY_CONFLICT, NO_NUMBERS, CHANNEL_UNAVAILABLE or CANCEL_TOO_EARLY"
          },
          "429": {
            "description": "RATE_LIMITED; data.retryAfter is seconds"
          },
          "503": {
            "description": "TEMPORARILY_UNAVAILABLE"
          }
        }
      }
    },
    "/api/v1/orders": {
      "get": {
        "summary": "List API orders",
        "parameters": [
          {
            "name": "active",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "orders": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Order"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "INVALID_INPUT"
          },
          "401": {
            "description": "BAD_KEY"
          },
          "409": {
            "description": "Business conflict, including PRICE_CHANGED, IDEMPOTENCY_CONFLICT, NO_NUMBERS, CHANNEL_UNAVAILABLE or CANCEL_TOO_EARLY"
          },
          "429": {
            "description": "RATE_LIMITED; data.retryAfter is seconds"
          },
          "503": {
            "description": "TEMPORARILY_UNAVAILABLE"
          }
        }
      },
      "post": {
        "summary": "Buy a number",
        "description": "Reuse the same Idempotency-Key for retries of the same request. Never change parameters under an existing key. pending means a number is being found or an uncertain result is being verified; use GET to poll the same order. Channel 1 can search for up to 90 seconds with at most three attempts after explicit no-stock replies. Success returns immediately; an uncertain purchase is never repeated and verification may last longer than the search window. maxPrice caps the price charged to your balance for this number.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "service",
                  "country"
                ],
                "properties": {
                  "service": {
                    "type": "string"
                  },
                  "country": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "channelId": {
                    "type": "string",
                    "examples": [
                      "channel-1",
                      "channel-2"
                    ]
                  },
                  "maxPrice": {
                    "type": "number",
                    "exclusiveMinimum": 0
                  },
                  "idempotencyKey": {
                    "type": "string",
                    "maxLength": 128
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "order": {
                      "$ref": "#/components/schemas/Order"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "INVALID_INPUT"
          },
          "401": {
            "description": "BAD_KEY"
          },
          "409": {
            "description": "Business conflict, including PRICE_CHANGED, IDEMPOTENCY_CONFLICT, NO_NUMBERS, CHANNEL_UNAVAILABLE or CANCEL_TOO_EARLY"
          },
          "429": {
            "description": "RATE_LIMITED; data.retryAfter is seconds"
          },
          "503": {
            "description": "TEMPORARILY_UNAVAILABLE"
          }
        }
      }
    },
    "/api/v1/orders/{id}": {
      "get": {
        "summary": "Get own order",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "order": {
                      "$ref": "#/components/schemas/Order"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "INVALID_INPUT"
          },
          "401": {
            "description": "BAD_KEY"
          },
          "409": {
            "description": "Business conflict, including PRICE_CHANGED, IDEMPOTENCY_CONFLICT, NO_NUMBERS, CHANNEL_UNAVAILABLE or CANCEL_TOO_EARLY"
          },
          "429": {
            "description": "RATE_LIMITED; data.retryAfter is seconds"
          },
          "503": {
            "description": "TEMPORARILY_UNAVAILABLE"
          }
        }
      }
    },
    "/api/v1/orders/{id}/{action}": {
      "post": {
        "summary": "Cancel, finish or request another SMS",
        "description": "Cancellation is permitted only after cancelableAt and before a code is received. Do not assume a fixed two-minute delay.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "action",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "cancel",
                "finish",
                "resend"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "order": {
                      "$ref": "#/components/schemas/Order"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "INVALID_INPUT"
          },
          "401": {
            "description": "BAD_KEY"
          },
          "409": {
            "description": "Business conflict, including PRICE_CHANGED, IDEMPOTENCY_CONFLICT, NO_NUMBERS, CHANNEL_UNAVAILABLE or CANCEL_TOO_EARLY"
          },
          "429": {
            "description": "RATE_LIMITED; data.retryAfter is seconds"
          },
          "503": {
            "description": "TEMPORARILY_UNAVAILABLE"
          }
        }
      }
    }
  }
}
