counter.count

The counter.count command is used to retrieve count records in the counter system.

TR50 Request

// Pass OrgId to cdp.usage.data.org.hour to get hourly use of data
{
  "1": {
    "command": "counter.count",
    "params": {
      "type": "cdp.usage.data.org.hour",
      "field": "OrgId",
      "calc": "sum",
      "series": "hour",
      "last": "30d",
      "limit": 8,
      "searchables": "560ef49c681fdc7d1f015605"
    }
  }
}

The above example returns the aggregate for 1 day and not for the last 1 hour. If you want the aggregate for 1 hour then you need to set the series to hour instead of day ( "series": "day")

// Pass dir to cdp.usage.sms.conn.day to obtatin the direction of the SMS
{  
   "1":{  
      "command":"counter.count",
      "params":{  
         "calc":"sum",
         "field":"dir",
         "searchables":"connectionId",
         "series":"day",
         "last":"30d",
         "type":"cdp.usage.sms.conn.day"
      }
   }
}

Request Parameters

Name

Type Required

Description

type String  Yes Counter types that can be searched. See more on counter types.
field String   Counter type's fields that can be searched. Use counter.fields to discover the fields to use in the field parameter. For more details, see TR50 Request and Response in the counter.fields
series String Yes Series for calculating the data. It is possible to set the series to day, hour, 15min, 5min, or total. The total provides an aggregate of the entire interval that is being requested. For more details on data aggregation, see Data Aggregation.
calc String Yes Way to calculate aggregation:
  • avg - The average within the specified time period.
  • wavg - The time weighted average within the specified time period. 
  • nzwavg - The non-zero time weighted average within the specified time period. 
  • sum - The sum of the property values within the specified time period.
  • max - The maximum property value within the specified time period.
  • min - The minimum property value within the specified time period.
  • count - The count of the property values within the specified time period.

For more details on data aggregation, see Data Aggregation.

orables Array   Limit data by search in a logical OR fashion. For example, orgId1 OR orgId2. Fields can be searched in orables.
searchables Array   Limit data by search in a logical AND fashion. For example, orgId1 AND orgId2. Fields can be searched in searchables. 
*One of the following parameter is required. The start is used together with the end to define the start and end time.
start String Yes* When doing a definite time period request this is the timestamp for the start of the specified time window.
end String When doing a definite time period request this is the timestamp for the end of the specified time window.
limit Integer Limits the number of results returned.
last String When doing a last period of time request this specifies the last X amount of time in seconds (s), minutes (m), hours (h), or days (d).
records Integer When doing a last number of records request this specifies the number of records to return.

TR50 Response

If the command is sent successfully a success message and the property value are returned. Otherwise, an error and error message will be returned.

 {
  "1": {
    "success": true,
    "params": {
      "534c36e53100460721000051": [
        6.21,
        4.583,
        6.012,
        3.65,
        4.126,
        5.793,
        7.55,
        6.428
      ],
      "queryTime": 13,
      "ts": [
        "2017-03-16T00:00:00Z",
        "2017-03-15T00:00:00Z",
        "2017-03-14T00:00:00Z",
        "2017-03-13T00:00:00Z",
        "2017-03-12T00:00:00Z",
        "2017-03-11T00:00:00Z",
        "2017-03-10T00:00:00Z",
        "2017-03-09T00:00:00Z"
      ]
    }
  }
}
{  
   "1":{  
      "success":true,
      "params":{  
         "mo":[  
            0,
            1
         ],
         "mt":[  
            1,
            1
         ],
         "queryTime":51,
         "ts":[  
            "2019-08-16T00:00:00Z",
            "2019-08-05T00:00:00Z"
         ]
      }
   }
}

Response Parameters

Name Type Description
params Array Array of data grouped by Field.
queryTime Integer Time it took to run the query in ms.
ts Array Array of timestamps corresponding to params.