> ## Documentation Index
> Fetch the complete documentation index at: https://help.dingtalk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Convert groupId to groupKey

> If you only have the groupId field, call this API to obtain the groupKey.

Call this API to convert the groupId of an attendance group to a groupKey. The groupKey is the identifier field used in the new version of attendance groups. Some attendance groups require groupKey as a parameter. If you only have the groupId field of an attendance group, call this API to obtain the groupKey.

## Request

| **Basic Information** | |
| - | - |
| HTTP URL | [https://api.dingtalk.io/topapi/attendance/groups/idtokey](https://api.dingtalk.io/topapi/attendance/groups/idtokey) |
| HTTP Method | POST |
| Supported app types | appType-Internal app　appType-Third-party enterprise app |
| Required permissions | permission-qyapi\_attendance\_group\_read-Attendance group query permission |

### Query Parameters

| Name | Type | Required | Example | Description |
| - | - | - | - | - |
| access\_token | String | Yes | 6d1bxxxx | The app credential used to call this API.   - For an Internal app, obtain it by calling the [Obtain the access\_token of an Internal App](https://help.dingtalk.io/open/development/obtain-orgapp-token) API. - For a Third-party enterprise app, obtain it by calling the Obtain the access\_token of a Third-party Enterprise API. |

### Request Body

| Name | Type | Required | Example | Description |
| - | - | - | - | - |
| op\_user\_id | String | No | user01 | The userId of the operator. |
| group\_id | Number | Yes | 1586536 | The attendance group ID. Call the [Batch Obtain Attendance Group Details](https://help.dingtalk.io/open/development/batch-obtain-attendance-group-details.md) API to obtain the group\_id value. |

### Request Example

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/topapi/attendance/groups/idtokey" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=ea55fdxxxx64242a' \
-d 'group_id=12' \
-d 'op_user_id=123'
```

Java

```java theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/attendance/groups/idtokey");
OapiAttendanceGroupsIdtokeyRequest req = new OapiAttendanceGroupsIdtokeyRequest();
req.setOpUserId("user01");
req.setGroupId(1586536L);
OapiAttendanceGroupsIdtokeyResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
```

Python

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import dingtalk.api

req=dingtalk.api.OapiAttendanceGroupsIdtokeyRequest("https://api.dingtalk.io/topapi/attendance/groups/idtokey")

req.op_user_id="123"
req.group_id=12
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
```

PHP

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');

$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiAttendanceGroupsIdtokeyRequest;
$req->setOpUserId("123");
$req->setGroupId("12");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/attendance/groups/idtokey");
```

C#

```csharp theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/attendance/groups/idtokey");
OapiAttendanceGroupsIdtokeyRequest req = new OapiAttendanceGroupsIdtokeyRequest();
req.OpUserId = "123";
req.GroupId = 12L;
OapiAttendanceGroupsIdtokeyResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);
```

## Response

### Response Body

| Name | Type | Example | Description |
| - | - | - | - |
| result | String | 0151E0223B1xxxx | The attendance group ID. |
| errcode | Number | 0 | The return code. |
| errmsg | String | ok | The description of the return code. |
| request\_id | String | 3yt2gu3zz0qi | The request ID. |

### Response Body Example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode":0,
  "result":0151E0223B1xxxx,
  "errmsg":"ok",
  "request_id":"3yt2gu3zz0qi"
}
```

### Error Codes

If the call to this API returns an error, find a solution in the [Global Error Codes](https://help.dingtalk.io/open/development/server-api-error-codes-1.md) document based on the error message.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.