MOR API v2 automatic cdr exports

From Kolmisoft Wiki
Jump to navigationJump to search

Configure scheduled CDR delivery tasks through MOR API v2. Behavior matches SETTINGS → CDR → Export → Automatic in the GUI (see Automatic CDR Export for field meanings). Choose a template_id from cdr_export_templates or the GUI.

The API creates and updates export tasks and returns scheduling metadata (for example, next_run_at). It does not run an export immediately — the system scheduler delivers files when each task is due (same pipeline as the GUI).

All endpoints require a valid Bearer token, admin user type, and the matching v2_automatic_cdr_exports_* method on the user’s API permission group (section CDR Export).



Quick start =

Obtain a token (see MOR API v2 authentication), then:

# Create a monthly automatic export for a wholesale user
curl -s -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{
    "name": "Wholesale ACME monthly CDR",
    "period": "monthly",
    "timezone": "London",
    "cdr_export_at_time": "02:00:00",
    "monthly_export_day": 1,
    "template_id": 5,
    "send_cdr_to": "user",
    "send_to_user_id": 123,
    "query": { "s_user_id": 123, "s_call_type": "all" },
    "filename_prefix": "ACME_",
    "archive_extension": "tgz",
    "active": true
  }' \
  "https://your-mor.example/api/v2/automatic_cdr_exports"

# Read back the created task (use id from the POST response)
curl -s -H "Authorization: Bearer $TOKEN" \
  "https://your-mor.example/api/v2/automatic_cdr_exports/42"



Endpoints =

Method Path Permission Description
GET /automatic_cdr_exports v2_automatic_cdr_exports_index List tasks. Query: active (0/1), send_to_user_id, period, name (partial match), from, max_results.
GET /automatic_cdr_exports/{id} v2_automatic_cdr_exports_show Show one task.
POST /automatic_cdr_exports v2_automatic_cdr_exports_create Create a task. JSON body (flat or nested query object). Returns automatic_cdr_export with next_run_at.
PUT / PATCH /automatic_cdr_exports/{id} v2_automatic_cdr_exports_update Update settings (partial fields allowed on PATCH).
DELETE /automatic_cdr_exports/{id} v2_automatic_cdr_exports_destroy Delete a task (empty body on success).
PATCH /automatic_cdr_exports/{id}/active v2_automatic_cdr_exports_update_active Set active state explicitly: {"active": true} or {"active": false} (not a toggle).



Request body =

Settings: name, active, period (hourly, daily, weekly, bi-weekly, monthly, only_once), timezone, cdr_export_at_time (HH:MM:SS), monthly_export_day, template_id, filename_prefix, archive_extension.

For only_once also send s_from, s_till, and cdr_export_at_datetime (ISO 8601 datetimes).

Delivery (send_cdr_to): user (requires send_to_user_id), email (requires send_to_email), ftp, or sftp. FTP/SFTP delivery requires the corresponding server paths to be configured in MOR; the API accepts the task even when paths are missing — delivery may fail at runtime.

Call filters (query object): same fields as the GUI export query — for example s_user_id, s_device, s_call_type, s_provider, s_destination, s_did_pattern, calls_from_users, calls_to_users, calls_via_dids, and related options.



Example responses =

Create (201):

{
  "automatic_cdr_export": {
    "id": 42,
    "name": "Wholesale ACME monthly CDR",
    "active": 1,
    "period": "monthly",
    "timezone": "London",
    "template_id": 5,
    "template_name": "My template",
    "send_cdr_to": "user",
    "send_to_user_id": 123,
    "next_run_at": "2026-07-01 02:00:00",
    "last_run_at": "",
    "cdr_export_at_time": "02:00:00",
    "monthly_export_day": 1,
    "query": { "s_user_id": 123, "s_call_type": "all" }
  }
}

Validation (422):

{
  "error": "Automatic CDR export was not created",
  "details": {
    "template_id": ["Template must be selected"]
  }
}

Not found (404): { "error": "Automatic CDR export was not found" }

ACL denied (401): { "errors": "API method not permitted: v2_automatic_cdr_exports_create" }

Unauthorized role (401): { "errors": "Unauthorized" } — accountant and user types cannot call these endpoints.



See also