خدمة دليل SDK للمشرف
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتيح لك خدمة "دليل SDK للمشرف" استخدام واجهة برمجة تطبيقات الدليل في "SDK للمشرف" ضمن Apps Script. تتيح واجهة برمجة التطبيقات هذه لمشرفي نطاقات Google Workspace (بما في ذلك المورّدين) إمكانية إدارة الأجهزة والمجموعات والمستخدمين والكيانات الأخرى في نطاقاتهم.
مراجع
للحصول على معلومات تفصيلية حول هذه الخدمة، يُرجى الاطّلاع على
المستندات المرجعية الخاصة بواجهة برمجة التطبيقات
Directory API في حزمة Admin SDK. مثل جميع الخدمات المتقدّمة في Apps Script، تستخدم خدمة "دليل" في Admin SDK الكائنات والطرق والمعلَمات نفسها التي تستخدمها واجهة برمجة التطبيقات العامة. لمزيد من المعلومات، اطّلِع على كيفية تحديد تواقيع الطرق.
للإبلاغ عن مشاكل والحصول على دعم آخر، يُرجى الاطّلاع على
دليل دعم دليل Admin SDK.
نموذج التعليمات البرمجية
يستخدم نموذج الرمز البرمجي أدناه الإصدار 1 من واجهة برمجة التطبيقات.
عرض قائمة بجميع المستخدمين
تعرض هذه العيّنة جميع المستخدمين في نطاق مرتّبين حسب الاسم الأول.
الحصول على مستخدم
يحصل هذا النموذج على مستخدم من خلال عنوان بريده الإلكتروني ويسجّل جميع بياناته كسلسلة JSON.
إضافة مستخدم
يضيف هذا النموذج مستخدمًا جديدًا إلى النطاق، ويتضمّن المعلومات المطلوبة فقط. للاطّلاع على القائمة الكاملة بحقول المستخدمين، يُرجى الرجوع إلى المستندات المرجعية الخاصة بواجهة برمجة التطبيقات.
إنشاء اسم مستعار
ينشئ هذا النموذج اسمًا مستعارًا (لقبًا) للمستخدم.
عرض كل المجموعات
يسرد هذا النموذج جميع المجموعات في النطاق.
إضافة عضو إلى المجموعة
يضيف هذا النموذج مستخدمًا إلى مجموعة حالية في النطاق.
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThe Admin SDK Directory service enables Google Workspace administrators to manage domain resources like users, groups, and devices within Apps Script using the Directory API.\u003c/p\u003e\n"],["\u003cp\u003eThis advanced service requires enabling both the Admin SDK and the specific service before use, and it mirrors the functionality of the public Directory API.\u003c/p\u003e\n"],["\u003cp\u003eSample code snippets demonstrate common tasks like listing and managing users, creating aliases, and handling groups and their members via the Admin SDK Directory service.\u003c/p\u003e\n"],["\u003cp\u003eBefore using the sample code, remember to enable the Admin SDK, replace placeholder values with your specific data, and refer to the documentation for details on API usage and error handling.\u003c/p\u003e\n"]]],[],null,["# Admin SDK Directory Service\n\nThe Admin SDK Directory service allows you to use the Admin SDK's\n[Directory API](/admin-sdk/directory) in Apps Script. This API gives\nadministrators of Google Workspace domains (including\nresellers) the ability to\nmanage devices, groups, users, and other entities in their domains.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced). Additionally, the Admin SDK must be enabled on your domain, as described in the API's [prerequisites documentation](/admin-sdk/directory/v1/guides/prerequisites).\n\nReference\n---------\n\nFor detailed information on this service, see the\n[reference documentation](/admin-sdk/directory/v1/reference) for the Admin SDK\nDirectory API. Like all advanced services in Apps Script, the Admin SDK\nDirectory service uses the same objects, methods, and parameters as the public\nAPI. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[Admin SDK Directory support guide](/admin-sdk/directory/support).\n\nSample code\n-----------\n\nThe sample code below uses [version 1](/admin-sdk/directory/v1/reference) of\nthe API.\n\n### List all users\n\nThis sample lists all the users in a domain sorted by first name. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Lists all the users in a domain sorted by first name.\n * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/list\n */\nfunction listAllUsers() {\n let pageToken;\n let page;\n do {\n page = AdminDirectory.Users.list({\n domain: 'example.com',\n orderBy: 'givenName',\n maxResults: 100,\n pageToken: pageToken\n });\n const users = page.users;\n if (!users) {\n console.log('No users found.');\n return;\n }\n // Print the user's full name and email.\n for (const user of users) {\n console.log('%s (%s)', user.name.fullName, user.primaryEmail);\n }\n pageToken = page.nextPageToken;\n } while (pageToken);\n}\n```\n\n### Get user\n\nThis sample gets a user by their email address and logs all of their data as a\nJSON string. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Get a user by their email address and logs all of their data as a JSON string.\n * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/get\n */\nfunction getUser() {\n // TODO (developer) - Replace userEmail value with yours\n const userEmail = 'liz@example.com';\n try {\n const user = AdminDirectory.Users.get(userEmail);\n console.log('User data:\\n %s', JSON.stringify(user, null, 2));\n } catch (err) {\n // TODO (developer)- Handle exception from the API\n console.log('Failed with error %s', err.message);\n }\n}\n```\n\n### Add user\n\nThis sample adds a new user to the domain, including only the required\ninformation. For the full list of user fields, see the API's\n[reference documentation](/admin-sdk/directory/v1/reference/users/insert). \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Adds a new user to the domain, including only the required information. For\n * the full list of user fields, see the API's reference documentation:\n * @see https://developers.google.com/admin-sdk/directory/v1/reference/users/insert\n */\nfunction addUser() {\n let user = {\n // TODO (developer) - Replace primaryEmail value with yours\n primaryEmail: 'liz@example.com',\n name: {\n givenName: 'Elizabeth',\n familyName: 'Smith'\n },\n // Generate a random password string.\n password: Math.random().toString(36)\n };\n try {\n user = AdminDirectory.Users.insert(user);\n console.log('User %s created with ID %s.', user.primaryEmail, user.id);\n } catch (err) {\n // TODO (developer)- Handle exception from the API\n console.log('Failed with error %s', err.message);\n }\n}\n```\n\n### Create alias\n\nThis sample creates an alias (nickname) for a user. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Creates an alias (nickname) for a user.\n * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/users.aliases/insert\n */\nfunction createAlias() {\n // TODO (developer) - Replace userEmail value with yours\n const userEmail = 'liz@example.com';\n let alias = {\n alias: 'chica@example.com'\n };\n try {\n alias = AdminDirectory.Users.Aliases.insert(alias, userEmail);\n console.log('Created alias %s for user %s.', alias.alias, userEmail);\n } catch (err) {\n // TODO (developer)- Handle exception from the API\n console.log('Failed with error %s', err.message);\n }\n}\n```\n\n### List all groups\n\nThis sample lists all the groups in the domain. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Lists all the groups in the domain.\n * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups/list\n */\nfunction listAllGroups() {\n let pageToken;\n let page;\n do {\n page = AdminDirectory.Groups.list({\n domain: 'example.com',\n maxResults: 100,\n pageToken: pageToken\n });\n const groups = page.groups;\n if (!groups) {\n console.log('No groups found.');\n return;\n }\n // Print group name and email.\n for (const group of groups) {\n console.log('%s (%s)', group.name, group.email);\n }\n pageToken = page.nextPageToken;\n } while (pageToken);\n}\n```\n\n### Add group member\n\nThis sample adds a user to an existing group in the domain. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Adds a user to an existing group in the domain.\n * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/members/insert\n */\nfunction addGroupMember() {\n // TODO (developer) - Replace userEmail value with yours\n const userEmail = 'liz@example.com';\n // TODO (developer) - Replace groupEmail value with yours\n const groupEmail = 'bookclub@example.com';\n const member = {\n email: userEmail,\n role: 'MEMBER'\n };\n try {\n AdminDirectory.Members.insert(member, groupEmail);\n console.log('User %s added as a member of group %s.', userEmail, groupEmail);\n } catch (err) {\n // TODO (developer)- Handle exception from the API\n console.log('Failed with error %s', err.message);\n }\n}\n```"]]