OpenAPI: Difference between revisions

From MiRTA PBX documentation
Jump to navigation Jump to search
No edit summary
No edit summary
Line 104: Line 104:
curl "https://pbx.example.com/openapi.php/extensions?tenant=TENANTCODE&key=APIKEY"
curl "https://pbx.example.com/openapi.php/extensions?tenant=TENANTCODE&key=APIKEY"
</pre>
</pre>
Using header authentication:
<pre>
curl \
  -H "X-API-Key: APIKEY" \
  "https://pbx.example.com/openapi.php/extensions?tenant=TENANTCODE"
</pre>
=== Example Response ===
<syntaxhighlight lang="json">
[
  {
    "id": 101,
    "number": "100",
    "name": "Reception",
    "tech": "PJSIP"
  },
  {
    "id": 102,
    "number": "101",
    "name": "Office",
    "tech": "SIP"
  }
]
</syntaxhighlight>
== Response Fields ==
{| class="wikitable"
! Field
! Type
! Description
|-
| <code>id</code>
| integer
| Extension internal ID
|-
| <code>number</code>
| string
| Extension number
|-
| <code>name</code>
| string
| Extension display name
|-
| <code>tech</code>
| string
| Extension technology, for example <code>SIP</code>, <code>PJSIP</code>, <code>VIRTUAL</code>, or <code>CUSTOM</code>
|}
 
== Error Responses ==
 
Errors are returned as JSON.
 
=== Missing API Key ===
 
<syntaxhighlight lang="json">
{
  "error": {
    "code": "missing_api_key",
    "message": "Missing API key."
  }
}
</syntaxhighlight>
 
=== Invalid API Key ===
 
<syntaxhighlight lang="json">
{
  "error": {
    "code": "invalid_api_key",
    "message": "Invalid API key."
  }
}
</syntaxhighlight>
 
=== Tenant Not Found ===

Revision as of 07:45, 25 May 2026

Overview

openapi.php is the JSON API endpoint based on the OpenAPI specification.

The API uses the existing MirtaPBX API keys:

  • Full API key: APIKEY
  • Read-only API key: READONLYAPIKEY

Both global and tenant-level keys are supported.

The first implemented API object is extension, with a list endpoint returning extension ID, number, name, and technology.

OpenAPI Specification

The OpenAPI specification is available from:

openapi.php
openapi.php?spec=1
openapi.php/openapi.json
openapi.php/swagger.json

The response is an OpenAPI 3.0.3 JSON document.

Authentication

The API key can be provided in any of these ways.

Query Parameter

openapi.php/extensions?tenant=TENANTCODE&key=APIKEY
X-API-Key: APIKEY

Bearer Token

Authorization: Bearer APIKEY

API Key Scope

Tenant API Key

When using a tenant-level API key, the tenant parameter is required.

openapi.php/extensions?tenant=TENANTCODE&key=TENANT_API_KEY

Global API Key

When using the global API key, tenant is optional.

If tenant is provided, only that tenant's extensions are returned.

If tenant is omitted, extensions from all tenants are returned.

openapi.php/extensions?key=GLOBAL_API_KEY

List Extensions

Endpoint

GET openapi.php/extensions

Alternative compatibility format:

openapi.php?object=extension&action=list

Parameters

Name Required Description
key Yes, unless using header auth Full or read-only API key
tenant Required for tenant keys Tenant code or tenant name

Example Request

curl "https://pbx.example.com/openapi.php/extensions?tenant=TENANTCODE&key=APIKEY"

Using header authentication:

curl \
  -H "X-API-Key: APIKEY" \
  "https://pbx.example.com/openapi.php/extensions?tenant=TENANTCODE"

Example Response

<syntaxhighlight lang="json"> [

 {
   "id": 101,
   "number": "100",
   "name": "Reception",
   "tech": "PJSIP"
 },
 {
   "id": 102,
   "number": "101",
   "name": "Office",
   "tech": "SIP"
 }

] </syntaxhighlight>

Response Fields

Field Type Description
id integer Extension internal ID
number string Extension number
name string Extension display name
tech string Extension technology, for example SIP, PJSIP, VIRTUAL, or CUSTOM

Error Responses

Errors are returned as JSON.

Missing API Key

<syntaxhighlight lang="json"> {

 "error": {
   "code": "missing_api_key",
   "message": "Missing API key."
 }

} </syntaxhighlight>

Invalid API Key

<syntaxhighlight lang="json"> {

 "error": {
   "code": "invalid_api_key",
   "message": "Invalid API key."
 }

} </syntaxhighlight>

Tenant Not Found