Skip to main content
Version: 25.03

Read formula

Enterprise

This endpoint is part of Countly Enterprise. To get access, contact sales or compare versions. Existing customers can reach the support portal with questions.

Endpoint​

/o/calculated_metrics/metric

Overview​

Returns a single formula document. Also supports mode=has_reports to return report usage count.

Authentication​

Pass api_key or auth_token as a query parameter, or send countly-token as a header. See Authentication.

Permissions​

  • Standard read mode requires formulas Read permission.
  • mode=has_reports does not apply formula visibility filtering and returns report count for metric_id within the app.

Request Parameters​

ParameterTypeRequiredDescription
app_idStringYesTarget app ID.
_idStringConditionalRequired for standard read mode. Formula ID to fetch.
modeStringNoSet has_reports to return report count instead of formula details.
metric_idStringConditionalRequired when mode=has_reports.
for_widgetsBoolean/StringNoIf provided, standard mode returns only _id and title.
api_keyStringConditionalRequired if auth_token is not provided.
auth_tokenStringConditionalRequired if api_key is not provided.

Examples​

/o/calculated_metrics/metric?
app_id=64f5c0d8f4f7ac0012ab3456&
_id=67bd31c92e7f0b0012ab4567
/o/calculated_metrics/metric?
app_id=64f5c0d8f4f7ac0012ab3456&
mode=has_reports&
metric_id=67bd31c92e7f0b0012ab4567

Response​

Success Response (Standard Read)​

{
"result": {
"_id": "67bd31c92e7f0b0012ab4567",
"title": "Revenue per Session",
"description": "Revenue divided by sessions",
"key": "revenue_per_session",
"visibility": "global",
"format": "float",
"dplaces": 2,
"unit": "USD",
"formula": "[...]",
"shared_email_edit": [],
"app": "64f5c0d8f4f7ac0012ab3456",
"formula_hash": "8e49d217047eafee994c3c8a4a1efcbb",
"owner_id": "64f5c0d8f4f7ac0012ab9999"
}
}

Success Response (mode=has_reports)​

{
"result": {
"count": 3
}
}

Response Fields​

FieldTypeDescription
resultObjectFormula document in standard mode; object with count in has_reports mode.
result.countNumberNumber of formula-related report tasks (has_reports mode only).

Error Responses​

No explicit error response is returned by this handler for standard read; missing/unauthorized formula returns an empty object ({}).

Behavior​

  • Standard read mode applies visibility rules (global, owner, or shared email).
  • Standard response excludes the expression field.
  • for_widgets returns minimized fields (_id, title) in standard mode.
  • mode=has_reports counts related entries in long_tasks using metric_id.
Implementation details

Database Collections

CollectionUsed forData touched by this endpoint
countly.calculated_metricsEndpoint data sourceStores endpoint-related records this endpoint reads or modifies.
countly.long_tasksBackground task trackingStores long-task lifecycle records for asynchronous endpoint processing.