نمونه کد برای API توکن‌های ثبت نام مدیریت کروم

برای مرور کلی ویژگی‌های API، به Chrome Management Enrollment Tokens API مراجعه کنید.

تمام درخواست‌های نمایش داده شده در این صفحه از متغیرهای زیر استفاده می‌کنند:

  • توکن $TOKEN - توکن OAuth 2.0
  • $CUSTOMER - شناسه مشتری یا به عبارت دیگر my_customer

ایجاد توکن ثبت نام

برای ایجاد یک توکن ثبت نام جدید برای یک دستگاه مرورگر، از نقطه پایانی /enrollmentTokens با HTTP POST استفاده کنید. می‌توانید به صورت اختیاری یک پارامتر پرس و جوی enrollmentTokenId را برای اختصاص یک شناسه توکن سفارشی مشخص کنید.

درخواست

  curl -X POST \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enrollmentTokens" \
  -d '{
    "tokenType": "ENROLLMENT_TOKEN_TYPE_CHROME_BROWSER",
    "orgUnitId": "03ph8a2z3v"
  }'

پاسخ

{
  "name": "customers/<customerId>/enrollmentTokens/<tokenPermanentId>",
  "tokenPermanentId": "<tokenPermanentId>",
  "token": "<tokenValue>",
  "customerId": "<customerId>",
  "orgUnitId": "03ph8a2z3v",
  "state": "ENROLLMENT_TOKEN_STATE_ACTIVE",
  "createTime": "2024-04-23T22:00:00.000Z",
  "creatorId": "user@example.com",
  "tokenType": "ENROLLMENT_TOKEN_TYPE_CHROME_BROWSER"
}

بازیابی توکن ثبت نام

برای بازیابی یک توکن ثبت نام واحد، از نقطه پایانی /enrollmentTokens/{token_permanent_id} با HTTP GET استفاده کنید.

درخواست

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enrollmentTokens/<tokenPermanentId>"

پاسخ

{
  "name": "customers/<customerId>/enrollmentTokens/<tokenPermanentId>",
  "tokenPermanentId": "<tokenPermanentId>",
  "token": "<tokenValue>",
  "customerId": "<customerId>",
  "orgUnitId": "03ph8a2z3v",
  "state": "ENROLLMENT_TOKEN_STATE_ACTIVE",
  "createTime": "2024-04-23T22:00:00.000Z",
  "creatorId": "user@example.com",
  "tokenType": "ENROLLMENT_TOKEN_TYPE_CHROME_BROWSER"
}

توکن‌های ثبت نام لیست

برای فهرست کردن توکن‌های ثبت‌نام، از نقطه پایانی /enrollmentTokens با HTTP GET استفاده کنید. می‌توانید صفحه‌بندی را با استفاده از پارامترهای pageSize (حداکثر و پیش‌فرض ۱۰۰) و pageToken کنترل کنید. برای محدود کردن نتایج، یک filter مشخص کنید.

مثال‌هایی از پرس‌وجوهای فیلتر

# Filter by token state
filter=token_state=ACTIVE

# Filter by Organizational Unit path
filter=org_unit_path=/Marketing

# Filter by Organizational Unit path containing spaces
filter=org_unit_path='/Browser Management'

# Filter by Organizational Unit ID
filter=org_unit_id=03ph8a2z3v

# Filter by token state, Organizational Unit path, and device type
filter=token_state=ACTIVE AND org_unit_path=/Marketing AND device_type=CHROME_BROWSER

درخواست

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enrollmentTokens?pageSize=2&filter=token_state=ACTIVE"

پاسخ

{
  "enrollmentTokens": [
    {
      "name": "customers/<customerId>/enrollmentTokens/<tokenPermanentId1>",
      "tokenPermanentId": "<tokenPermanentId1>",
      "token": "<tokenValue1>",
      "customerId": "<customerId>",
      "orgUnitId": "03ph8a2z3v",
      "state": "ENROLLMENT_TOKEN_STATE_ACTIVE",
      "createTime": "2024-04-23T22:00:00.000Z",
      "creatorId": "user1@example.com",
      "tokenType": "ENROLLMENT_TOKEN_TYPE_CHROME_BROWSER"
    },
    {
      "name": "customers/<customerId>/enrollmentTokens/<tokenPermanentId2>",
      "tokenPermanentId": "<tokenPermanentId2>",
      "token": "<tokenValue2>",
      "customerId": "<customerId>",
      "orgUnitId": "03ph8a2z3v",
      "state": "ENROLLMENT_TOKEN_STATE_ACTIVE",
      "createTime": "2024-04-23T21:30:00.000Z",
      "creatorId": "user2@example.com",
      "tokenType": "ENROLLMENT_TOKEN_TYPE_CHROME_BROWSER"
    }
  ],
  "nextPageToken": "<nextPageToken>"
}

ابطال توکن ثبت نام

برای لغو یک توکن ثبت نام، از نقطه پایانی /enrollmentTokens/{token_permanent_id}:revoke با HTTP POST استفاده کنید.

درخواست

  curl -X POST \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enrollmentTokens/<tokenPermanentId>:revoke" \
  -d '{}'

پاسخ

{
  "name": "customers/<customerId>/enrollmentTokens/<tokenPermanentId>",
  "tokenPermanentId": "<tokenPermanentId>",
  "token": "<tokenValue>",
  "customerId": "<customerId>",
  "orgUnitId": "03ph8a2z3v",
  "state": "ENROLLMENT_TOKEN_STATE_REVOKED",
  "createTime": "2024-04-23T22:00:00.000Z",
  "revokeTime": "2024-04-24T10:15:00.000Z",
  "creatorId": "user@example.com",
  "revokerId": "admin@example.com",
  "tokenType": "ENROLLMENT_TOKEN_TYPE_CHROME_BROWSER"
}