Skip to main content
Call this API to get the total number of employees.

API call description

This API is not restricted by the Contacts permission scope.

Request

Basic information
HTTP URLhttps://oapi.dingtalk.io/topapi/user/count
HTTP MethodPOST
Supported app typesappType-Internal app, appType-Third-party enterprise app
Required permissionspermission-qyapi_get_member-Read permission for user information

Query parameter

NameTypeRequiredExampleDescription
access_tokenStringYesbE74xxxxThe app credential used to call this API. - For an internal app, obtain it through the API for getting the access_token of an internal app. - For a third-party enterprise app, obtain it through the API for getting the access_token of a third-party enterprise.

Request body

NameTypeRequiredExampleDescription
only_activeBooleanYesfalseWhether to include the number of employees who have not activated DingTalk: - false: Include employees who have not activated DingTalk. - true: Only include employees who have activated DingTalk.

Request example

curl -X POST "https://oapi.dingtalk.io/topapi/user/count" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=7a1bee78-57cb-4a05-9316-0341b1ca303f' \
-d 'only_active=false'
Java
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/user/count");
OapiUserCountRequest req = new OapiUserCountRequest();
req.setOnlyActive(false);
OapiUserCountResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
Python
import dingtalk.api

req=dingtalk.api.OapiUserCountRequest("https://oapi.dingtalk.io/topapi/user/count")

req.only_active=false
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
PHP
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');

$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiUserCountRequest;
$req->setOnlyActive("false");
$resp = $c->execute($req, $access_token, "https://oapi.dingtalk.io/topapi/user/count");
C#
IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/user/count");
OapiUserCountRequest req = new OapiUserCountRequest();
req.OnlyActive = false;
OapiUserCountResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);

Response

Response body

NameTypeExampleDescription
request_idStringo38h5bztjoucThe request ID.
errcodeNumber0The status code. 0 indicates that the call succeeded.
errmsgStringInvalid access_tokenThe error message returned when the call failed.
resultCountUserResponseThe returned result.
countNumber4The number of employees.

Response body example

{
    "errcode": 0,
    "errmsg":"ok",
    "result": {
        "count": 4
    },
    "request_id": "40k5v0mgbzyh"
}

Error codes

If an error is returned when you call this API, refer to the Global error codes document to find a solution based on the error message.
Error code (errcode)Error message (errmsg)Solution
400002Parameter is emptyMake sure all required parameters are provided.
40035Invalid parameterMake sure the parameters meet the requirements in the documentation above.
-1System busyTry again later.