> ## 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.

# Mendapatkan semua departemen induk dari pengguna tertentu

> Panggil API DingTalk ini untuk mendapatkan daftar semua departemen induk milik pengguna tertentu. Tidak dibatasi oleh cakupan izin Kontak, cocok untuk integrasi kontak organisasi.

Panggil API ini untuk mendapatkan semua departemen induk milik pengguna tertentu. API ini tidak dibatasi oleh cakupan izin Kontak.

## Permintaan

| **Informasi dasar**         |                                                                                                                                |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| URL HTTP                    | [https://api.dingtalk.io/topapi/v2/department/listparentbyuser](https://api.dingtalk.io/topapi/v2/department/listparentbyuser) |
| Metode HTTP                 | POST                                                                                                                           |
| Tipe aplikasi yang didukung | appType-Aplikasi internalappType-Aplikasi perusahaan pihak ketiga                                                              |
| Izin yang diperlukan        | permission-qyapi\_get\_department\_list-Izin baca untuk informasi departemen Kontak                                            |

### Parameter query

| Nama          | Tipe   | Wajib | Contoh   | Deskripsi                                                                                                                                                                                                                                                                                                                                      |
| ------------- | ------ | ----- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_token | String | Ya    | bE74xxxx | Kredensial aplikasi yang digunakan untuk memanggil API ini.   - Untuk Aplikasi internal, dapatkan melalui API untuk mendapatkan [access\_token dari Aplikasi internal](/id/open/development/obtain-orgapp-token). - Untuk Aplikasi perusahaan pihak ketiga, dapatkan melalui API untuk mendapatkan access\_token dari perusahaan pihak ketiga. |

### Isi permintaan

| Nama   | Tipe   | Wajib | Contoh | Deskripsi                                   |
| ------ | ------ | ----- | ------ | ------------------------------------------- |
| userid | String | Ya    | 100    | ID pengguna dari pengguna yang akan dicari. |

### Contoh permintaan

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/topapi/v2/department/listparentbyuser" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=f3c2f4xxxxf65767' \
-d 'userid=100'
```

Java

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/department/listparentbyuser");
OapiV2DepartmentListparentbyuserRequest req = new OapiV2DepartmentListparentbyuserRequest();
req.setUserid("100");
OapiV2DepartmentListparentbyuserResponse 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.OapiV2DepartmentListparentbyuserRequest("https://api.dingtalk.io/topapi/v2/department/listparentbyuser")

req.userid="100"
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 OapiV2DepartmentListparentbyuserRequest;
$req->setUserid("100");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/v2/department/listparentbyuser");
```

C#

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/department/listparentbyuser");
OapiV2DepartmentListparentbyuserRequest req = new OapiV2DepartmentListparentbyuserRequest();
req.Userid = "100";
OapiV2DepartmentListparentbyuserResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);
```

## Respons

### Isi respons

| Nama                   | Tipe                         | Contoh         | Deskripsi                                           |
| ---------------------- | ---------------------------- | -------------- | --------------------------------------------------- |
| errcode                | Number                       | 0              | Kode pengembalian.                                  |
| request\_id            | String                       | nfe328zf67ec   | ID permintaan.                                      |
| errmsg                 | String                       | Invalid userid | Pesan error yang dikembalikan saat panggilan gagal. |
| result                 | DeptListParentByUserResponse |                | Hasil yang dikembalikan.                            |
| parent\_list           | DeptParentResponse\[]        |                | Kumpulan daftar departemen induk.                   |
| parent\_dept\_id\_list | Number\[]                    | \[456, 123, 1] | Daftar departemen induk.                            |

### Contoh isi respons

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode": 0,
  "errmsg":"ok",
  "result": {
    "parent_list": [
      {
        "parent_dept_id_list": [
          37xxxx95,
          1
        ]
      }
    ]
  },
  "request_id": "nfe328zf67ec"
}
```

### Kode error

Jika terjadi error saat memanggil API ini, temukan solusinya di dokumen [Kode error global](/id/open/development/server-api-error-codes-1) berdasarkan pesan error.

| Kode error (errcode) | Pesan error (errmsg)   | Solusi                                                |
| -------------------- | ---------------------- | ----------------------------------------------------- |
| 43007                | Authorization required | Pastikan access\_token memiliki Izin yang diperlukan. |
| 33012                | Invalid userId         | Pastikan userId sudah benar.                          |
| 400002               | Invalid parameter      | Pastikan parameter dimasukkan sesuai ketentuan.       |
| -1                   | System busy            | Coba lagi nanti.                                      |
