Skip to main content

Tenant

The Tenant object is supported by the MiRTA PBX OpenAPI endpoint. This object is managed at system scope and requires a global API key.

Object Summary

PropertyValue
Objecttenant
Primary path/tenants
ID fieldte_id
Label fieldte_name
Primary source tablete_tenants
Required on createte_name, te_code
Path aliases/tenants

Endpoint Patterns

ActionExample pattern
ListGET https://pbx.example.com/pbx/openapi.php/tenants
Get by IDGET https://pbx.example.com/pbx/openapi.php/tenants/OBJECT_ID
CreatePOST https://pbx.example.com/pbx/openapi.php/tenants
UpdatePATCH https://pbx.example.com/pbx/openapi.php/tenants/OBJECT_ID
DeleteDELETE https://pbx.example.com/pbx/openapi.php/tenants/OBJECT_ID

Accepted Field Aliases

Request fieldSource field
namete_name
codete_code
billingcodete_billingcode
billing_codete_billingcode
timezonete_timezone
routing_profile_idte_rp_id
campaign_routing_profile_idte_campaign_rp_id
fax_routing_profile_idte_fax_rp_id

Examples

List Tenants

Returns the tenants visible to the key and scope.

curl -H "X-API-Key: GLOBAL_API_KEY" \
  "https://pbx.example.com/pbx/openapi.php/tenants"

To filter the list with a full or read-only legacy global key, pass tenant as a tenant code or name. The selector uses SQL LIKE. Use % for any sequence of characters or _ for a single character. Omit tenant to list all tenants available to the key.

curl --get 'https://pbx.example.com/pbx/openapi.php/tenants' \
  -H 'X-API-Key: GLOBAL_API_KEY' \
  --data-urlencode 'tenant=%Example%'

An advanced key needs global permission and access to listTenants. Supply one exact code or name within its allowed scope, or omit tenant to list that scope.

HTTP statusMeaning
400invalid_tenant when the selector is supplied in a form other than a string.
404tenant_not_found when the selector has no match.
409ambiguous_tenant when the exact selector for an advanced key is ambiguous.
500database_error when the legacy tenant lookup or the tenant list query fails.
503api_key_unavailable when the advanced key policy or exact tenant lookup is unavailable.

Get Tenant

Reads one object by its internal ID.

curl -H "X-API-Key: GLOBAL_API_KEY" \
  "https://pbx.example.com/pbx/openapi.php/tenants/OBJECT_ID"

Create Tenant

Creates a new object. Use the short aliases shown above or the source field names.

curl -X POST \
  -H "X-API-Key: GLOBAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Docs API Tenant",
  "code": "DOCSAPI",
  "timezone": "Europe/Rome"
}' \
  "https://pbx.example.com/pbx/openapi.php/tenants"

Edit Tenant

Updates only the supplied fields.

curl -X PATCH \
  -H "X-API-Key: GLOBAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "routing_profile_id": 3,
  "te_payment_type": "Post Paid"
}' \
  "https://pbx.example.com/pbx/openapi.php/tenants/OBJECT_ID"

Delete Tenant

Deletes the object. Check references before deleting configuration used by routing or reporting.

curl -X DELETE \
  -H "X-API-Key: GLOBAL_API_KEY" \
  "https://pbx.example.com/pbx/openapi.php/tenants/OBJECT_ID"

Tenant Initialization

POST /tenants requires a full global API key. It creates the tenant and its related records in one transaction.

curl -X POST \
  -H "X-API-Key: GLOBAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Acme",
  "code": "ACME",
  "parking": {"start": 700, "end": 720, "hosted": ""},
  "user_ids": [12],
  "usergroup_ids": [3]
}' \
  "https://pbx.example.com/pbx/openapi.php/tenants"
  • Global new-item defaults for tenants and parking apply first; explicit request values override them. Tenant settings are copied from the global new-item defaults. APIKEY and READONLYAPIKEY defaults set to RANDOM16 become generated 16-character keys. Empty PARKTIMEOUT, MAXCALLDURATION and DIALTIMEOUT receive 120, 7200 and 60.
  • One parking lot named after the tenant code is created, by default 700–720 on an automatic server. Use the parking object, or pk_start/pk_end/pk_hosted. Asterisk is not reloaded and no server placement is performed.
  • user_ids and usergroup_ids give existing users and groups access to the tenant. The default custom destination restriction mode is applied; ctselected, an array of custom type IDs, overrides the configured exceptions.
  • Codes need at least two characters without spaces. Duplicate codes return 409 and the tenant license limit is checked before saving.
  • The response includes an initialization summary. Errors include rolled_back: true confirms that nothing was saved. HTTP 503 tenant_commit_unknown returns the tenant_id; inspect that tenant before retrying.

These inputs apply only to creation. To change an existing tenant, use the tenant, settings, parking, user and user-group operations.

Tenant Server Placement

GET /tenants/TENANT_ID/placement shows which cluster servers a tenant uses, with a full or read-only global key. POST changes it and requires a full global key. Tenant keys cannot inspect or change placement. Use the numeric tenant ID in the path and omit tenant.

curl -H "X-API-Key: GLOBAL_API_KEY" \
  "https://pbx.example.com/pbx/openapi.php/tenants/42/placement"

curl -X POST -H "X-API-Key: GLOBAL_API_KEY" -H "Content-Type: application/json" \
  -d '{"settings":{"preferred_queue_node_id":2},"assignments":{"queues":2}}' \
  "https://pbx.example.com/pbx/openapi.php/tenants/42/placement"

GET returns the placement settings, the raw stored preferences, the resolved defaults, the current assignment of each service and the server inventory with eligibility and diagnostics. Eligible means registered with a usable peer name; it does not prove that the server is healthy.

Body objectMeaning
settingsDefaults and preferences for new objects: cronjob_node_id, campaign_node_id, fax_node_id, preferred_queue_node_id, preferred_parking_node_id. Existing objects are not moved.
assignmentsMoves every current object of a service in the tenant: queues, parkinglots, conferences, campaigns, cronjobs. System jobs and UPLOADRECORDING jobs are excluded.
  • Values are server IDs, not peer names. Supply at least one field; omitted fields are preserved. 0 clears a preference or explicit host so the object inherits the default or automatic placement again.
  • Changing campaign_node_id also updates the tenant DEFAULTCAMPAIGNSERVER setting.
  • Stop running campaigns before changing their placement. A running or pending cron job returns 409 placement_busy; database lock conflicts also return 409, so reload and retry later.
  • Queue changes are notified to every registered server after saving; queue_refresh reports which servers accepted the notification. Parking modules are not reloaded, so moving parking lots may need a scheduled restart, as in the web editor.
  • The save is a single transaction. Errors include rolled_back; 503 placement_commit_unknown means the outcome is unknown, so inspect GET before retrying.

Common Errors

ErrorMeaning
missing_api_keyNo API key was supplied in the query string, X-API-Key, or bearer token.
invalid_api_keyThe supplied key does not match the tenant or global API key.
tenant_requiredA tenant code is required for tenant-scoped writes or tenant-key reads.
read_only_api_keyThe key can read data but cannot create, update, or delete objects.
missing_required_fieldA required create field is missing.