यह कैसे काम करता है

शुरुआती जानकारी

'पहले से तैयार डिवाइस' सुविधा वाले एपीआई की मदद से, डिवाइस रीसेलर अपने इंटिग्रेशन को ऑटोमेट कर सकते हैं. आपके संगठन के बिक्री टूल, 'पहले से तैयार डिवाइस' सुविधा में मदद कर सकते हैं. इससे आपके उपयोगकर्ता और आपके ग्राहक ज़्यादा बेहतर तरीके से काम कर पाते हैं. अपने उपयोगकर्ताओं की मदद करने के लिए, इस एपीआई का इस्तेमाल करें:

  • खरीदे गए डिवाइस, ग्राहक के 'पहले से तैयार डिवाइस' सुविधा वाले खाते में असाइन करें.
  • अपने ग्राहक का 'पहले से तैयार डिवाइस' सुविधा वाला खाता बनाएं.
  • अपने संगठन का टेलीफ़ोन और ऑर्डर मेटाडेटा को डिवाइसों से अटैच करें.
  • आपके ग्राहकों को असाइन किए गए डिवाइसों के बारे में रिपोर्ट बनाएं.

इस दस्तावेज़ में, एपीआई के बारे में जानकारी और पैटर्न के बारे में बताया गया है. अगर आपको एपीआई को खुद एक्सप्लोर करना है, तो Java, .NET या Python के लिए क्विकस्टार्ट की सुविधा आज़माएं.

एपीआई के सिद्धांत

ग्राहक और डिवाइस, वे मुख्य संसाधन हैं जिनका इस्तेमाल इस एपीआई में किया जाता है. ग्राहक बनाने के लिए, create पर कॉल करें. दावा एपीआई के तरीकों का इस्तेमाल करके डिवाइस बनाए जा सकते हैं (नीचे देखें). आपका संगठन 'पहले से तैयार डिवाइस' सुविधा वाले पोर्टल का इस्तेमाल करके, ग्राहक और डिवाइस भी बना सकता है.

डिवाइस और ग्राहक संसाधन संबंध

ग्राहक
वे कंपनियां जिन्हें आपका संगठन डिवाइस बेचता है. ग्राहकों के पास name और एक ID है. किसी ग्राहक के डिवाइसों पर दावा करने या उन्हें ढूंढने के लिए, इसका इस्तेमाल करें. ज़्यादा जानने के लिए, Customer देखें.
डिवाइस
ऐसा Android या ChromeOS डिवाइस जिसे आपका संगठन किसी ग्राहक को बेचता है. डिवाइस में हार्डवेयर आईडी, मेटाडेटा, और ग्राहक दावे होते हैं. एपीआई का मुख्य काम डिवाइस हैं, इसलिए उनका इस्तेमाल करीब-करीब सभी तरीकों में किया जाता है. ज़्यादा जानने के लिए, Device देखें.
DeviceIdentifier
मैन्युफ़ैक्चर किए गए डिवाइस की पहचान करने के लिए, IMEI या MEID जैसे हार्डवेयर आईडी को इनकैप्सुलेट करता है. जिस डिवाइस को ढूंढना है, अपडेट करना है या जिस पर दावा करना है उसे टारगेट करने के लिए, DeviceIdentifier का इस्तेमाल करें. ज़्यादा जानने के लिए, आइडेंटिफ़ायर पढ़ें.
DeviceMetadata
डिवाइस के लिए मेटाडेटा के की-वैल्यू पेयर को स्टोर करता है. अपने संगठन का मेटाडेटा सेव करने के लिए, DeviceMetadata का इस्तेमाल करें. ज़्यादा जानने के लिए, डिवाइस का मेटाडेटा पढ़ें.

आपका ऐप्लिकेशन, एपीआई के जिन तरीकों और संसाधनों का इस्तेमाल कर सकता है उनकी सूची बनाने के लिए, एपीआई का रेफ़रंस देखें.

ग्राहक बनाएं

Android डिवाइसों के लिए, रीसेलर को अपने ग्राहक की ओर से ग्राहक खाता बनाना होगा. 'पहले से तैयार डिवाइस' सुविधा वाले पोर्टल को ऐक्सेस करने के लिए, ग्राहक इस खाते का इस्तेमाल करेंगे. इससे वे अपने डिवाइसों के लिए प्रावधान की सेटिंग कॉन्फ़िगर कर पाएंगे. यह उन ChromeOS डिवाइसों के लिए ज़रूरी नहीं है जिनके पास पहले से Google Workspace खाता है. इसका इस्तेमाल वे प्रॉविज़निंग सेटिंग को कॉन्फ़िगर करने के लिए करेंगे.

पहले से तैयार डिवाइसों के लिए ग्राहक खाते बनाने के लिए, create एपीआई तरीके को कॉल किया जा सकता है. 'पहले से तैयार डिवाइस' सुविधा वाले पोर्टल में, आपके ग्राहकों को कंपनी का नाम दिखता है. इसलिए, आपके ऐप्लिकेशन के उपयोगकर्ता को यह पुष्टि करनी होगी कि यह सही है. ग्राहक बनाने के बाद, ग्राहक के नाम में बदलाव नहीं किया जा सकता.

मालिक बनने के लिए, आपको कम से कम एक ऐसा कॉर्पोरेट ईमेल पता शामिल करना होगा जो Google खाते से जुड़ा हो. API के साथ, निजी Gmail खातों का इस्तेमाल नहीं किया जा सकता. अगर ग्राहक को खाता जोड़ने में मदद चाहिए, तो Google खाता जोड़ें से निर्देश भेजें.

एपीआई को कॉल करके ग्राहक बनाने के बाद, ग्राहक अपने कर्मचारियों के लिए पोर्टल का ऐक्सेस मैनेज करते हैं — आपके पास एपीआई का इस्तेमाल करके उपयोगकर्ताओं की सूची में बदलाव करने का विकल्प नहीं होता. नीचे दिया गया स्निपेट दिखाता है कि ग्राहक कैसे बनाए जा सकते हैं:

Java

// Provide the customer data as a Company type.
// The API requires a name and owners.
Company customer = new Company();
customer.setCompanyName("XYZ Corp");
customer.setOwnerEmails(Arrays.asList("liz@example.com", "darcy@example.com"));
customer.setAdminEmails(Collections.singletonList("jane@example.com"));

// Use our reseller ID for the parent resource name.
String parentResource = String.format("partners/%d", PARTNER_ID);

// Call the API to create the customer using the values in the company object.
CreateCustomerRequest body = new CreateCustomerRequest();
body.setCustomer(customer);
Company response = service.partners().customers().create(parentResource, body).execute();

.NET

// Provide the customer data as a Company type.
// The API requires a name and owners.
var customer = new Company
{
    CompanyName = "XYZ Corp",
    OwnerEmails = new String[] { "liz@example.com", "darcy@example.com" },
    AdminEmails = new String[] { "jane@example.com" }
};

// Use our reseller ID for the parent resource name.
var parentResource = String.Format("partners/{0}", PartnerId);

// Call the API to create the customer using the values in the company object.
var body = new CreateCustomerRequest
{
    Customer = customer
};
var request = service.Partners.Customers.Create(body, parentResource);
var response = request.Execute();

Python

# Provide the customer data as a Company type. The API requires
# a name and at least one owner.
company = {'companyName':'XYZ Corp', \
  'ownerEmails':['liz@example.com', 'darcy@example.com'], \
  'adminEmails':['jane@example.com']}

# Use our reseller ID for the parent resource name.
parent_resource = 'partners/{0}'.format(PARTNER_ID)

# Call the API to create the customer using the values in the company object.
response = service.partners().customers().create(parent=parent_resource,
    body={'customer':company}).execute()

अपने ग्राहक के कर्मचारियों के मालिक और एडमिन की भूमिकाओं के बारे में ज़्यादा जानने के लिए, पोर्टल उपयोगकर्ता पढ़ें.

ग्राहकों के लिए डिवाइस पर दावा करें

डिवाइस खरीदने के बाद, ग्राहकों को अपने खाते में इन डिवाइसों के लिए प्रावधान की सेटिंग कॉन्फ़िगर करनी होगी. डिवाइस पर दावा करने से, डिवाइस 'पहले से तैयार डिवाइस' सुविधा में जुड़ जाता है और ग्राहक को प्रॉविज़निंग सेटिंग कॉन्फ़िगर करने की सुविधा मिलती है.

डिवाइस के प्रॉविज़निंग रिकॉर्ड में, पहले से तैयार डिवाइस के लिए एक सेक्शन है. डिवाइस असाइन करने के लिए, आपको किसी ग्राहक के लिए, रिकॉर्ड के पहले से तैयार डिवाइस वाले सेक्शन पर दावा करना होगा. ग्राहक से partners.devices.claim या partners.devices.claimAsync तरीकों को तर्क के तौर पर कॉल करें. sectionType की वैल्यू के तौर पर हमेशा SECTION_TYPE_ZERO_TOUCH दें.

किसी दूसरे ग्राहक के लिए उसी डिवाइस पर दावा करने से पहले, आपको उस ग्राहक के डिवाइस का दावा छोड़ना होगा (नीचे देखें). नया डिवाइस बनाते समय दावे के तरीके DeviceIdentifier फ़ील्ड की validate करते हैं. इनमें IMEI, MEID, सीरियल नंबर, मैन्युफ़ैक्चरर का नाम, और मॉडल, और ChromeOS डिवाइसों के लिए पुष्टि किए गए आईडी की जानकारी शामिल है.

नीचे दिया गया स्निपेट किसी डिवाइस पर दावा करने का तरीका दिखाता है:

Java

// Identify the device to claim.
DeviceIdentifier identifier = new DeviceIdentifier();
// The manufacturer value is optional but recommended for cellular devices
identifier.setManufacturer("Google");
identifier.setImei("098765432109875");

// Create the body to connect the customer with the device.
ClaimDeviceRequest body = new ClaimDeviceRequest();
body.setDeviceIdentifier(identifier);
body.setCustomerId(customerId);
body.setSectionType("SECTION_TYPE_ZERO_TOUCH");

// Claim the device.
ClaimDeviceResponse response = service.partners().devices().claim(PARTNER_ID, body).execute();

.NET

// Identify the device to claim.
var deviceIdentifier = new DeviceIdentifier
{
    // The manufacturer value is optional but recommended for cellular devices
    Manufacturer = "Google",
    Imei = "098765432109875"
};

// Create the body to connect the customer with the device.
ClaimDeviceRequest body = new ClaimDeviceRequest
{
    DeviceIdentifier = deviceIdentifier,
    CustomerId = CustomerId,
    SectionType = "SECTION_TYPE_ZERO_TOUCH"
};

// Claim the device.
var response = service.Partners.Devices.Claim(body, PartnerId).Execute();

Python

# Identify the device to claim.
# The manufacturer value is optional but recommended for cellular devices
device_identifier = {'manufacturer':'Google', 'imei':'098765432109875'}

# Create the body to connect the customer with the device.
request_body = {'deviceIdentifier':device_identifier, \
    'customerId':customer_id, \
    'sectionType':'SECTION_TYPE_ZERO_TOUCH'}

# Claim the device.
response = service.partners().devices().claim(partnerId=PARTNER_ID,
    body=request_body).execute()

ऐसे डिवाइस जिन पर दावा नहीं किया जा रहा है

आपका संगठन किसी ग्राहक के डिवाइस पर दावा छोड़ सकता है. डिवाइस पर दावा न करने पर, उसे 'पहले से तैयार डिवाइस' सुविधा से हटा दिया जाता है. रीसेलर, उस डिवाइस से दावा हटा सकता है जिसे वह किसी दूसरे खाते पर माइग्रेट करना चाहता है, वापस करना चाहता है या जिस पर गलती से दावा किया गया था. किसी ग्राहक से डिवाइस पर दावा हटाने के लिए, partners.devices.unclaim या partners.devices.unclaimAsync तरीके को कॉल करें.

वेंडर

वेंडर नेटवर्क में रीसेलर पार्टनर, ग्लोबल रीसेलर नेटवर्क के स्थानीय ऑपरेटर या आपकी ओर से डिवाइस बेचने वाले किसी भी संगठन के प्रतिनिधि के तौर पर, वेंडर की मदद ली जा सकती है. वेंडर आपके उपयोगकर्ताओं, ग्राहकों, और डिवाइसों को अलग-अलग करने में आपकी मदद करते हैं:

  • आपके बनाए गए वेंडर, 'पहले से तैयार डिवाइस' सुविधा वाला आपका खाता या दूसरे लोगों के खाते नहीं देख सकते.
  • वेंडर के ग्राहकों और डिवाइसों को देखा जा सकता है. साथ ही, वेंडर के डिवाइसों का रजिस्ट्रेशन रद्द भी किया जा सकता है. हालांकि, आप अपने वेंडर के ग्राहकों को डिवाइस असाइन नहीं कर सकते हैं.

पोर्टल का इस्तेमाल करके अपने संगठन के लिए वेंडर बनाएं — आप एपीआई का इस्तेमाल नहीं कर सकते. नया वेंडर बनाने के लिए, खाते में आपके पास मालिक की भूमिका होनी चाहिए. अगर आपके संगठन में वेंडर हैं, तो अपने वेंडर की सूची बनाने के लिए partners.vendors.list को कॉल करें और अपने वेंडर के ग्राहकों से संपर्क करने के लिए, partners.vendors.customers.list को कॉल करें. इस उदाहरण में वेंडर के ग्राहकों के लिए सेवा की शर्तों की स्थिति दिखाने वाली रिपोर्ट प्रिंट करने के लिए इन दोनों तरीकों का इस्तेमाल किया गया है:

Java

// First, get the organization's vendors.
String parentResource = String.format("partners/%d", PARTNER_ID);
ListVendorsResponse results = service.partners().vendors().list(parentResource).execute();
if (results.getVendors() == null) {
  return;
}

// For each vendor, report the company name and a maximum 5 customers.
for (Company vendor: results.getVendors()) {
  System.out.format("\n%s customers\n", vendor.getCompanyName());
  System.out.println("---");
  // Use the vendor's API resource name as the parent resource.
  AndroidProvisioningPartner.Partners.Vendors.Customers.List customerRequest =
      service.partners().vendors().customers().list(vendor.getName());
  customerRequest.setPageSize(5);
  ListVendorCustomersResponse customerResponse = customerRequest.execute();

  List<Company> customers = customerResponse.getCustomers();
  if (customers == null) {
    System.out.println("No customers");
    break;
  } else {
    for (Company customer: customers) {
      System.out.format("%s: %s\n",
          customer.getCompanyName(),
          customer.getTermsStatus());
    }
  }
}

.NET

// First, get the organization's vendors.
var parentResource = String.Format("partners/{0}", PartnerId);
var results = service.Partners.Vendors.List(parentResource).Execute();
if (results.Vendors == null)
{
    return;
}

// For each vendor, report the company name and a maximum 5 customers.
foreach (Company vendor in results.Vendors)
{
    Console.WriteLine("\n{0} customers", vendor);
    Console.WriteLine("---");
    // Use the vendor's API resource name as the parent resource.
    PartnersResource.VendorsResource.CustomersResource.ListRequest customerRequest =
        service.Partners.Vendors.Customers.List(vendor.Name);
    customerRequest.PageSize = 5;
    var customerResponse = customerRequest.Execute();

    IList<Company> customers = customerResponse.Customers;
    if (customers == null)
    {
        Console.WriteLine("No customers");
        break;
    }
    else
    {
        foreach (Company customer in customers)
        {
            Console.WriteLine("{0}: {1}", customer.Name, customer.TermsStatus);
        }
    }
}

Python

# First, get the organization's vendors.
parent_resource = 'partners/{0}'.format(PARTNER_ID)
vendor_response = service.partners().vendors().list(
    parent=parent_resource).execute()
if 'vendors' not in vendor_response:
  return

# For each vendor, report the company name and a maximum 5 customers.
for vendor in vendor_response['vendors']:
  print '\n{0} customers'.format(vendor['companyName'])
  print '---'
  # Use the vendor's API resource name as the parent resource.
  customer_response = service.partners().vendors().customers().list(
      parent=vendor['name'], pageSize=5).execute()
  if 'customers' not in customer_response:
    print 'No customers'
    break
  for customer in customer_response['customers']:
    print '  {0}: {1}'.format(customer['name'], customer['termsStatus'])

अगर आपके पास कई डिवाइस हैं, तो आपके लिए यह जानना ज़रूरी हो सकता है कि किस रीसेलर या वेंडर ने डिवाइस पर दावा किया है. अंकों वाले रीसेलर आईडी पाने के लिए, डिवाइस के दावे के रिकॉर्ड में resellerId फ़ील्ड की वैल्यू की जांच करें.

आपका संगठन, वेंडर के दावा किए गए डिवाइस से दावा हटा सकता है. डिवाइसों में बदलाव करने वाले दूसरे एपीआई कॉल के लिए, एपीआई तरीके को कॉल करने से पहले आपको यह जांच करनी चाहिए कि आपके संगठन ने डिवाइस पर दावा किया है या नहीं. यहां दिए गए उदाहरण में बताया गया है कि ऐसा कैसे किया जा सकता है:

Java

// Get the devices claimed for two customers: one of our organization's
// customers and one of our vendor's customers.
FindDevicesByOwnerRequest body = new FindDevicesByOwnerRequest();
body.setSectionType("SECTION_TYPE_ZERO_TOUCH");
body.setCustomerId(Arrays.asList(resellerCustomerId, vendorCustomerId));
body.setLimit(MAX_PAGE_SIZE);
FindDevicesByOwnerResponse response =
    service.partners().devices().findByOwner(PARTNER_ID, body).execute();
if (response.getDevices() == null) {
  return;
}

for (Device device: response.getDevices()) {
  // Confirm the device was claimed by our reseller and not a vendor before
  // updating metadata in another method.
  for (DeviceClaim claim: device.getClaims()) {
    if (claim.getResellerId() == PARTNER_ID) {
      updateDeviceMetadata(device.getDeviceId());
      break;
    }
  }
}

.NET

// Get the devices claimed for two customers: one of our organization's
// customers and one of our vendor's customers.
FindDevicesByOwnerRequest body = new FindDevicesByOwnerRequest
{
    Limit = MaxPageSize,
    SectionType = "SECTION_TYPE_ZERO_TOUCH",
    CustomerId = new List<long?>
    {
        resellerCustomerId,
        vendorCustomerId
    }
};
var response = service.Partners.Devices.FindByOwner(body, PartnerId).Execute();
if (response.Devices == null)
{
    return;
}

foreach (Device device in response.Devices)
{
    // Confirm the device was claimed by our reseller and not a vendor before
    // updating metadata in another method.
    foreach (DeviceClaim claim in device.Claims)
    {
        if (claim.ResellerId == PartnerId)
        {
            UpdateDeviceMetadata(device.DeviceId);
            break;
        }
    }
}

Python

# Get the devices claimed for two customers: one of our organization's
# customers and one of our vendor's customers.
request_body = {'limit':MAX_PAGE_SIZE, \
  'pageToken':None, \
  'customerId':[reseller_customer_id, vendor_customer_id], \
  'sectionType':'SECTION_TYPE_ZERO_TOUCH'}
response = service.partners().devices().findByOwner(partnerId=PARTNER_ID,
    body=request_body).execute()

for device in response['devices']:
  # Confirm the device was claimed by our reseller and not a vendor before
  # updating metadata in another method.
  for claim in device['claims']:
    if claim['resellerId'] == PARTNER_ID:
      update_device_metadata(device['deviceId'])
      break

लंबे समय तक चलने वाली बैच कार्रवाइयां

एपीआई में, डिवाइस के तरीकों के एसिंक्रोनस वर्शन शामिल होते हैं. इन तरीकों से कई डिवाइसों को एक साथ प्रोसेस किया जा सकता है. वहीं, सिंक्रोनस तरीके, हर एपीआई अनुरोध के लिए एक डिवाइस को प्रोसेस करते हैं. एसिंक्रोनस तरीके के नामों में एक साथ काम करने वाली प्रोसेस सफ़िक्स होता है, जैसे कि claimAsync.

प्रोसेसिंग पूरी होने से पहले, एसिंक्रोनस एपीआई तरीके एक नतीजा देते हैं. एसिंक्रोनस तरीके से आपके ऐप्लिकेशन (या टूल) को उपयोगकर्ताओं के लिए रिस्पॉन्सिव बने रहने में भी मदद मिलती है, जब तक वे लंबे समय तक चलने वाली कार्रवाई के पूरा होने का इंतज़ार करते हैं. आपके ऐप्लिकेशन को समय-समय पर कार्रवाई की स्थिति की जांच करनी चाहिए.

ऑपरेशंस

लंबे समय से चल रही बैच कार्रवाई को ट्रैक करने के लिए, Operation का इस्तेमाल किया जाता है. एसिंक्रोनस तरीके को पूरा किया गया कॉल रिस्पॉन्स में, कार्रवाई का रेफ़रंस देता है. नीचे दिया गया JSON स्निपेट, updateMetadataAsync को कॉल करने के बाद एक सामान्य जवाब दिखाता है:

{
  "name": "operations/apibatchoperation/1234567890123476789"
}

हर ऑपरेशन में अलग-अलग टास्क की सूची होती है. इस कार्रवाई में मौजूद टास्क की स्थिति और उनके नतीजों के बारे में जानकारी पाने के लिए, operations.get को कॉल करें. नीचे दिया गया स्निपेट दिखाता है कि ऐसा कैसे किया जा सकता है. अपने ऐप्लिकेशन में, आपको सभी गड़बड़ियों को ठीक करना होगा.

Java

// Build out the request body to apply the same order number to a customer's
// purchase of 2 devices.
UpdateMetadataArguments firstUpdate = new UpdateMetadataArguments();
firstUpdate.setDeviceMetadata(metadata);
firstUpdate.setDeviceId(firstTargetDeviceId);

UpdateMetadataArguments secondUpdate = new UpdateMetadataArguments();
secondUpdate.setDeviceMetadata(metadata);
secondUpdate.setDeviceId(firstTargetDeviceId);

// Start the device metadata update.
UpdateDeviceMetadataInBatchRequest body = new UpdateDeviceMetadataInBatchRequest();
body.setUpdates(Arrays.asList(firstUpdate, secondUpdate));
Operation response = service
    .partners()
    .devices()
    .updateMetadataAsync(PARTNER_ID, body)
    .execute();

// Assume the metadata update started, so get the Operation for the update.
Operation operation = service.operations().get(response.getName()).execute();

.NET

// Build out the request body to apply the same order number to a customer's
// purchase of 2 devices.
var updates = new List<UpdateMetadataArguments>
{
    new UpdateMetadataArguments
    {
        DeviceMetadata = metadata,
        DeviceId = firstTargetDeviceId
    },
    new UpdateMetadataArguments
    {
        DeviceMetadata = metadata,
        DeviceId = secondTargetDeviceId
    }
};

// Start the device metadata update.
UpdateDeviceMetadataInBatchRequest body = new UpdateDeviceMetadataInBatchRequest
{
    Updates = updates
};
var response = service.Partners.Devices.UpdateMetadataAsync(body, PartnerId).Execute();

// Assume the metadata update started, so get the Operation for the update.
Operation operation = service.Operations.Get(response.Name).Execute();

Python

# Build out the request body to apply the same order number to a customer's
# purchase of 2 devices.
updates = [{'deviceMetadata':metadata,'deviceId':first_target_device_id},
    {'deviceMetadata':metadata,'deviceId':second_target_device_id}]

# Start the device metadata update.
response = service.partners().devices().updateMetadataAsync(
    partnerId=PARTNER_ID, body={'updates':updates}).execute()

# Assume the metadata update started, so get the Operation for the update.
operation = service.operations().get(name=response['name']).execute()

यह जानने के लिए कि कोई कार्रवाई पूरी हुई है या नहीं, true वैल्यू वाले done फ़ील्ड के लिए कार्रवाई देखें. अगर done मौजूद नहीं है या false है, तो कार्रवाई अब भी चल रही है.

जवाब

एक कार्रवाई पूरी होने के बाद एपीआई, कार्रवाई को नतीजे के साथ अपडेट करता है. भले ही, सभी या कोई भी टास्क पूरा न हुआ हो. response फ़ील्ड एक DevicesLongRunningOperationResponse ऑब्जेक्ट है, जो कार्रवाई के दौरान हर डिवाइस की प्रोसेसिंग के बारे में जानकारी देता है.

successCount फ़ील्ड की जांच करके अच्छी तरह से पता लगाएं कि कोई टास्क पूरा नहीं हुआ है या नहीं. साथ ही, बड़ी नतीजों की सूची में बार-बार टास्क करने से बचें. DevicesLongRunningOperationResponse का perDeviceStatus फ़ील्ड, OperationPerDevice इंस्टेंस की सूची है. इसमें हर डिवाइस के बारे में जानकारी मौजूद है. सूची का क्रम, ओरिजनल अनुरोध में मौजूद टास्क से मेल खाता है.

हर OperationPerDevice टास्क में एक result फ़ील्ड होता है. साथ ही, सर्वर को मिले अनुरोध के बारे में रिमाइंडर की खास जानकारी होती है. result फ़ील्ड का इस्तेमाल करके देखें कि टास्क कामयाब रहा है या नहीं.

नीचे दिया गया JSON स्निपेट, updateMetadataAsync पर कॉल करने के बाद, किसी कार्रवाई से मिलने वाले सामान्य रिस्पॉन्स का हिस्सा दिखाता है:

"response": {
  "perDeviceStatus": [
    {
      "result": {
        "deviceId": "12345678901234567",
        "status": "SINGLE_DEVICE_STATUS_SUCCESS"
      },
      "updateMetadata": {
        "deviceId": "12345678901234567",
        "deviceMetadata": {
          "entries": {
            "phonenumber": "+1 (800) 555-0100"
          }
        }
      }
    }
  ],
  "successCount": 1
}

प्रोग्रेस ट्रैक करें

अगर आपके ऐप्लिकेशन को प्रगति को ट्रैक करने की ज़रूरत है, तो आपको समय-समय पर ऑपरेशन को फिर से लाना होगा. metadata फ़ील्ड में DevicesLongRunningOperationMetadata एक इंस्टेंस होता है, जिससे आपके ऐप्लिकेशन को चल रही किसी कार्रवाई की हाल की प्रोग्रेस की जांच करने में मदद मिलती है. कार्रवाई की प्रोग्रेस ट्रैक करने के लिए, नीचे दी गई टेबल में दिए गए DevicesLongRunningOperationMetadata के फ़ील्ड का इस्तेमाल करें:

फ़ील्ड आम इस्तेमाल
processingStatus कार्रवाई के चलने पर, BATCH_PROCESS_PENDING से BATCH_PROCESS_IN_PROGRESS और फिर BATCH_PROCESS_PROCESSED में बदलाव किया जाता है.
progress प्रोसेस किए गए अपडेट का प्रतिशत. आपका ऐप्लिकेशन इसका इस्तेमाल, इवेंट खत्म होने में लगने वाले समय का अनुमान लगाने के लिए कर सकता है. कार्रवाई पूरी होने के दौरान, progress की वैल्यू 100 हो सकती है. इसलिए, यह जानने के लिए कि कोई कार्रवाई पूरी हो चुकी है या नहीं और उससे नतीजे मिल रहे हैं या नहीं, उसका done फ़ील्ड देखें.
devicesCount कार्रवाई के दौरान होने वाले अपडेट की संख्या दिखाता है. अगर एपीआई कुछ अपडेट को पार्स नहीं कर पाता है, तो यह आपके अनुरोध में मौजूद अपडेट की संख्या से अलग हो सकती है.

नीचे दिए गए उदाहरण में यह दिखाया गया है कि पोलिंग इंटरवल सेट करने के लिए, कोई ऐप्लिकेशन प्रोग्रेस मेटाडेटा का इस्तेमाल किस तरह कर सकता है. अपने ऐप्लिकेशन में, पोल कराने के लिए आपको ज़्यादा बेहतर टास्क रनर की ज़रूरत हो सकती है. आपको गड़बड़ी ठीक करने की सुविधा भी जोड़नी होगी.

Java

// Milliseconds between polling the API.
private static long MIN_INTERVAL = 2000;
private static long MAX_INTERVAL = 10000;

// ...
// Start the device metadata update.
Operation response = service
    .partners()
    .devices()
    .updateMetadataAsync(PARTNER_ID, body)
    .execute();
String operationName = response.getName();

// Start polling for completion.
long startTime = new Date().getTime();
while (true) {

  // Get the latest update on the operation's progress using the API.
  Operation operation = service.operations().get(operationName).execute();

  if (operation.get("done") != null && operation.getDone()) {
    // The operation is finished. Print the status.
    System.out.format("Operation complete: %s of %s successful device updates\n",
        operation.getResponse().get("successCount"),
        operation.getMetadata().get("devicesCount"));
    break;

  } else {
    // Estimate how long the operation *should* take - within min and max value.
    BigDecimal opProgress = (BigDecimal) operation.getMetadata().get("progress");
    double progress = opProgress.longValue();
    long interval = MAX_INTERVAL;
    if (progress > 0) {
      interval = (long) ((new Date().getTime() - startTime) *
          ((100.0 - progress) / progress));
    }
    interval = Math.max(MIN_INTERVAL, Math.min(interval, MAX_INTERVAL));

    // Sleep until the operation should be complete.
    Thread.sleep(interval);
  }
}

.NET

// Milliseconds between polling the API.
private static double MinInterval = 2000;
private static double MaxInterval = 10000;

// ...
// Start the device metadata update.
var response = service.Partners.Devices.UpdateMetadataAsync(body, PartnerId).Execute();
var operationName = response.Name;

// Start polling for completion.
var startTime = DateTime.Now;
while (true)
{

    // Get the latest update on the operation's progress using the API.
    Operation operation = service.Operations.Get(operationName).Execute();

    if (operation.Done == true)
    {
        // The operation is finished. Print the status.
        Console.WriteLine("Operation complete: {0} of {1} successful device updates",
                          operation.Response["successCount"],
                          operation.Metadata["devicesCount"]);
        break;
    }
    else
    {
        // Estimate how long the operation *should* take - within min and max value.
        double progress = (double)(long)operation.Metadata["progress"];
        double interval = MaxInterval;
        if (progress > 0)
        {
            interval = DateTime.Now.Subtract(startTime).TotalMilliseconds *
                                     ((100.0 - progress) / progress);
        }
        interval = Math.Max(MinInterval, Math.Min(interval, MaxInterval));

        // Sleep until the operation should be complete.
        System.Threading.Thread.Sleep((int)interval);
    }
}

Python

# Seconds between polling the API.
MIN_INTERVAL = 2;
MAX_INTERVAL = 10;

# ...
# Start the device metadata update
response = service.partners().devices().updateMetadataAsync(
  partnerId=PARTNER_ID, body={'updates':updates}).execute()

op_name = response['name']
start_time = time.time()

# Start polling for completion
while True:
  # Get the latest update on the operation's progress using the API
  op = service.operations().get(name=op_name).execute()

  if 'done' in op and op['done']:
    # The operation is finished. Print the status.
    print('Operation complete: {0} of {1} successful device updates'.format(
      op['response']['successCount'], op['metadata']['devicesCount']
    ))
    break
  else:
    # Estimate how long the operation *should* take - within min and max.
    progress = op['metadata']['progress']
    interval = MIN_INTERVAL
    if progress > 0:
      interval = (time.time() - start_time) * ((100.0 - progress) / progress)
    interval = max(MIN_INTERVAL, min(interval, MAX_INTERVAL))

    # Sleep until the operation should be complete.
    time.sleep(interval)

पोल कराने का ऐसा तरीका चुनें जो आपके ऐप्लिकेशन का इस्तेमाल करने वाले लोगों के लिए सही हो. कुछ ऐप्लिकेशन उपयोगकर्ताओं को नियमित रूप से होने वाले अपडेट से फ़ायदा मिल सकता है, बशर्ते वे प्रोसेस पूरी होने का इंतज़ार कर रहे हों.

पेज किए गए नतीजे

partners.devices.findByOwner एपीआई के तरीके से, डिवाइसों की बहुत बड़ी सूचियां मिल सकती हैं. रिस्पॉन्स साइज़ को कम करने के लिए, यह और एपीआई के दूसरे तरीके (जैसे कि partners.devices.findByIdentifier) पेज पर मौजूद नतीजे का इस्तेमाल करते हैं. पेज वाले नतीजों के साथ, आपका ऐप्लिकेशन बार-बार बड़ी सूचियों के लिए एक बार में एक ही पेज का अनुरोध कर सकता है और उसे प्रोसेस कर सकता है.

एपीआई तरीके को कॉल करने के बाद, देखें कि रिस्पॉन्स में nextPageToken के लिए वैल्यू शामिल है या नहीं. अगर nextPageToken, null नहीं है, तो आपका ऐप्लिकेशन इसका इस्तेमाल डिवाइस के दूसरे पेज फ़ेच करने के लिए कर सकता है. ऐसा करने के लिए, आपको इस तरीके को फिर से कॉल करना होगा. आपको limit पैरामीटर में डिवाइस की संख्या के लिए ऊपरी सीमा सेट करनी होगी. अगर nextPageToken null है, तो इसका मतलब है कि आपके ऐप्लिकेशन ने आखिरी पेज का अनुरोध किया है.

नीचे दिया गया उदाहरण दिखाता है कि आपका ऐप्लिकेशन डिवाइसों की सूची को, एक बार में एक पेज को कैसे प्रिंट कर सकता है:

Java

private static long MAX_PAGE_SIZE = 10;

// ...
/**
 * Demonstrates how to loop through paginated lists of devices.
 * @param pageToken       The token specifying which result page to return.
 * @throws IOException    If the zero-touch API call fails.
 */
private void printDevices(String pageToken) throws IOException {

  // Create the request body to find the customer's devices.
  FindDevicesByOwnerRequest body = new FindDevicesByOwnerRequest();
  body.setLimit(MAX_PAGE_SIZE);
  body.setSectionType("SECTION_TYPE_ZERO_TOUCH");
  body.setCustomerId(Collections.singletonList(targetCustomerId));

  // Call the API to get a page of Devices. Send a page token from the method
  // argument (might be None). If the page token is None, the API returns the first page.
  FindDevicesByOwnerResponse response =
      service.partners().devices().findByOwner(PARTNER_ID, body).execute();
  if (response.getDevices() == null) {
    return;
  }

  // Print the devices included in this page of results.
  for (Device device: response.getDevices()) {
    System.out.format("Device %s\n", device.getName());
  }
  System.out.println("---");

  // Check to see if another page of devices is available. If yes,
  // fetch and print the devices.
  if (response.getNextPageToken() != null) {
    this.printDevices(response.getNextPageToken());
  }
}

// ...
// Pass null to start printing the first page of devices.
printDevices(null);

.NET

private static int MaxPageSize = 10;

// ...
/// <summary>Demonstrates how to loop through paginated lists of devices.</summary>
/// <param name="pageToken">The token specifying which result page to return.</param>
private void PrintDevices(string pageToken)
{
    // Create the request body to find the customer's devices.
    FindDevicesByOwnerRequest body = new FindDevicesByOwnerRequest
    {
        PageToken = pageToken,
        Limit = MaxPageSize,
        SectionType = "SECTION_TYPE_ZERO_TOUCH",
        CustomerId = new List<long?>
        {
            targetCustomerId
        }
    };

    // Call the API to get a page of Devices. Send a page token from the method
    // argument (might be None). If the page token is None, the API returns the first page.
    var response = service.Partners.Devices.FindByOwner(body, PartnerId).Execute();
    if (response.Devices == null)
    {
        return;
    }

    // Print the devices included in this page of results.
    foreach (Device device in response.Devices)
    {
        Console.WriteLine("Device: {0}", device.Name);
    }
    Console.WriteLine("---");

    // Check to see if another page of devices is available. If yes,
    // fetch and print the devices.
    if (response.NextPageToken != null)
    {
        this.PrintDevices(response.NextPageToken);
    }
}

// ...
// Pass null to start printing the first page of devices.
PrintDevices(null);

Python

MAX_PAGE_SIZE = 10;

# ...
def print_devices(page_token):
  """Demonstrates how to loop through paginated lists of devices.

  Args:
    page_token: The token specifying which result page to return.
  """

   # Create the body to find the customer's devices.
  request_body = {'limit':MAX_PAGE_SIZE, \
    'pageToken':page_token, \
    'customerId':[target_customer_id], \
    'sectionType':'SECTION_TYPE_ZERO_TOUCH'}

  # Call the API to get a page of Devices. Send a page token from the method
  # argument (might be None). If the page token is None,
  # the API returns the first page.
  response = service.partners().devices().findByOwner(partnerId=PARTNER_ID,
    body=request_body).execute()

  # Print the devices included in this page of results.
  for device in response['devices']:
    print 'Device: {0}'.format(device['name'])
  print '---'

  # Check to see if another page of devices is available. If yes,
  # fetch and print the devices.
  if 'nextPageToken' in response:
    print_devices(response['nextPageToken'])

# ...
# Pass None to start printing the first page of devices.
print_devices(None);

अगले चरण

अब जब आपको पता है कि एपीआई कैसे काम करता है, तो Java, .NET या Python के क्विकस्टार्ट के साथ ये उदाहरण देखें.