Skip to content

Get Object Count

The Object Count API provides a way to obtain the following values from the server:

  • Number of objects in a table
  • Number of objects matching query
  • Number of related objects

Method:

GET / POST

Endpoint URL

The xxxx.backendless.app is a subdomain assigned to your application. For more information see the Client-side Setup section of this documentation.

https://xxxx.backendless.app/api/data/<table-name>/count?where=<whereClause> 

where:

Argument                Description
<table-name> name of the table to get an object count from.
<whereClause> Optional argument. If set, it is a search query used by the server it to determine the number of objects matching the condition. The value must be URL-encoded.

Request Headers

user-token:value-of-the-user-token-header-from-login

where:

Argument                Description
user-token Optional header. Contains a value returned by Backendless in a preceding user Login API call. If user-tokenis set in the request, the operation will be executed with the security policy associated with the currently logged in user. This means all permissions associated with the user and roles assigned to the user will be enforced by Backendless.

Request Body

Applies only to the POST operation.

{  
"distinct": true/false  
}

where:

Argument                Description
distinct When this parameter is set to true, identical objects are not counted in the data table. Note that if an object has a null value and the distinct parameter is set to true, then the object is not counted. The default value of this parameter is false.

Response Body:

The number of objects in a table (if the whereClause is not set), otherwise the number of objects matching the search query.

Example

Important

Make sure to replace xxxx in the domain name in the sample requests below to the one assigned to your application.

Total object count for a table:

The following sample request retrieves total number of objects in table Order:

curl "https://xxxx.backendless.app/api/data/Order/count"

Object count for a query:

The following sample request retrieves total number of objects in table Order which satisfy the condition of orderAmount > 100:

curl "https://xxxx.backendless.app/api/data/Order/count?where=orderAmount%20%3E%20100"

Related object count:

The following sample request retrieves total number of related "child" objects for a parent object. The parent table is Person. It contains a relation column called address pointing to the Addresstable. The query below retrieves a count of related child objects for a parent object with objectID of XXXX-XXXX-XXXX-XXXX. The whereClause query syntax for this scenario is:

Person[address].objectId = 'XXXX-XXXX-XXXX-XXXX'

The whereClause must be URL-encoded, which results in the following sample request:

curl "https://xxxx.backendless.app/api/data/Address/count?where=Person%5Baddress%5D.objectId%20%3D%20%27XXXX-XXXX-XXXX-XXXX%27"

Codeless Reference

data_service_get_objects_count

where:

Argument                Description
table name Name of the data table where to calculate the object count.
where clause Optional argument. If set, it is a search query used by the server it to determine the number of objects matching the condition. Refer to the Search With The Where Clause topic for more information.
distinct Used to return unique objects from the data table. Only custom properties/columns are considered in the query. Hence, if the data table contains a duplicate object, then it is not counted in the operation.

Returns the number of objects in a table (if the where clause is not set), otherwise the number of objects matching the search query.

Consider the following records in the employees data table:

data_service_example_get_objects_count_1

The example below counts specific objects in the data table since the where clause condition is set to exclude objects that contain the value 'Manager' in the column position. Thereby, objects with the 'Manager' values in the position column are not counted in the operation.

data_service_example_get_objects_count_2

The result of this operation will look as shown below after the Codeless logic runs:

data_service_example_bulk_update_4

Consider the data table below that contains two duplicate objects:

data_service_example_get_objects_count_3

The Codeless logic below has a where clause condition which is set to include in the operation only those objects that contain the value 'CEO' in the position column. The distinct parameter is set to true, hence the operation is set to count only unique objects, duplicates are skipped.

data_service_example_get_objects_count_5

The result of this operation will look as shown below after the Codeless logic runs:

data_service_example_get_objects_count_4