কিভাবে এটা কাজ করে

ভূমিকা

জিরো-টাচ এনরোলমেন্ট API ডিভাইস রিসেলারদের তাদের ইন্টিগ্রেশন স্বয়ংক্রিয় করতে সাহায্য করে। আপনার প্রতিষ্ঠানের বিক্রয় সরঞ্জামগুলি জিরো-টাচ এনরোলমেন্ট তৈরি করতে পারে—আপনার ব্যবহারকারী এবং আপনার গ্রাহকদের আরও বেশি উত্পাদনশীল করে তোলে। আপনার ব্যবহারকারীদের সাহায্য করতে API ব্যবহার করুন:

  • একটি গ্রাহকের জিরো-টাচ এনরোলমেন্ট অ্যাকাউন্টে কেনা ডিভাইসগুলি বরাদ্দ করুন৷
  • আপনার গ্রাহকের জিরো-টাচ এনরোলমেন্ট অ্যাকাউন্ট তৈরি করুন।
  • আপনার প্রতিষ্ঠানের টেলিফোন সংযুক্ত করুন এবং ডিভাইসে মেটাডেটা অর্ডার করুন।
  • আপনার গ্রাহকদের বরাদ্দ করা ডিভাইস সম্পর্কে প্রতিবেদন তৈরি করুন।

এই নথিটি এপিআই পরিচয় করিয়ে দেয় এবং নিদর্শনগুলি ব্যাখ্যা করে। আপনি যদি নিজে এপিআই অন্বেষণ করতে চান, তাহলে Java , .NET , বা Python এর জন্য একটি কুইকস্টার্ট চেষ্টা করুন৷

API ধারণা

গ্রাহক এবং ডিভাইসগুলি হল মূল সংস্থান যা আপনি API এ ব্যবহার করেন। গ্রাহক তৈরি করতে, create কল করুন। আপনি দাবি API পদ্ধতি ব্যবহার করে ডিভাইস তৈরি করতে পারেন ( নীচে দেখুন )। আপনার প্রতিষ্ঠান জিরো-টাচ এনরোলমেন্ট পোর্টাল ব্যবহার করে গ্রাহক এবং ডিভাইস তৈরি করতে পারে।

ডিভাইস এবং গ্রাহক সম্পদ সম্পর্ক

ক্রেতা
আপনার প্রতিষ্ঠান যে কোম্পানির কাছে ডিভাইস বিক্রি করে। গ্রাহকদের একটি name এবং একটি ID আছে। যখন আপনি দাবি করতে চান বা তাদের ডিভাইস খুঁজে পেতে চান তখন একজন গ্রাহককে ব্যবহার করুন। আরও জানতে, Customer দেখুন।
যন্ত্র
একটি জিরো-টাচ এনরোলমেন্ট-সক্ষম Android বা ChromeOS ডিভাইস যা আপনার প্রতিষ্ঠান একজন গ্রাহকের কাছে বিক্রি করে। ডিভাইসগুলিতে হার্ডওয়্যার আইডি, মেটাডেটা এবং গ্রাহকের দাবি রয়েছে। ডিভাইসগুলি এপিআই-এর কেন্দ্রীয়, তাই আপনি সেগুলি প্রায় সমস্ত পদ্ধতিতে ব্যবহার করেন। আরও জানতে, Device দেখুন।
ডিভাইস শনাক্তকারী
একটি তৈরি ডিভাইস সনাক্ত করতে IMEI বা MEID এর মতো হার্ডওয়্যার আইডিগুলিকে এনক্যাপসুলেট করে৷ আপনি যে ডিভাইসটি খুঁজে পেতে, আপডেট করতে বা দাবি করতে চান তা লক্ষ্য করতে একটি DeviceIdentifier ব্যবহার করুন৷ আরও জানতে, আইডেন্টিফায়ার পড়ুন।
ডিভাইস মেটাডেটা
ডিভাইসের জন্য মেটাডেটার মূল-মান জোড়া সঞ্চয় করে। আপনার প্রতিষ্ঠানের মেটাডেটা সংরক্ষণ করতে DeviceMetadata ব্যবহার করুন। আরও জানতে, ডিভাইস মেটাডেটা পড়ুন।

আপনার অ্যাপ ব্যবহার করতে পারে এমন সমস্ত API পদ্ধতি এবং সংস্থান তালিকাভুক্ত করতে, API রেফারেন্স দেখুন।

গ্রাহক তৈরি করুন

অ্যান্ড্রয়েড ডিভাইসগুলির জন্য, রিসেলার তাদের গ্রাহকের পক্ষে গ্রাহক অ্যাকাউন্ট তৈরি করার জন্য দায়ী৷ গ্রাহক তাদের ডিভাইসের জন্য প্রভিশনিং সেটিংস কনফিগার করতে জিরো-টাচ পোর্টাল অ্যাক্সেস করতে এই অ্যাকাউন্টটি ব্যবহার করবে। ChromeOS ডিভাইসগুলির জন্য এটি প্রয়োজনীয় নয়, যাদের আগে থেকেই একটি Google Workspace অ্যাকাউন্ট আছে যা তারা তাদের প্রভিশনিং সেটিংস কনফিগার করতে ব্যবহার করবে।

আপনি জিরো-টাচ নথিভুক্তির জন্য গ্রাহক অ্যাকাউন্ট তৈরি করতে API create পদ্ধতিতে কল করতে পারেন। যেহেতু আপনার গ্রাহকরা তাদের জিরো-টাচ এনরোলমেন্ট পোর্টালে কোম্পানির নাম দেখেন, আপনার অ্যাপের ব্যবহারকারীকে নিশ্চিত করা উচিত যে এটি সঠিক। আপনি গ্রাহক তৈরি করার পরে আপনি একজন গ্রাহকের নাম সম্পাদনা করতে পারবেন না।

মালিক হওয়ার জন্য আপনাকে Google অ্যাকাউন্টের সাথে যুক্ত অন্তত একটি কর্পোরেট ইমেল ঠিকানা অন্তর্ভুক্ত করতে হবে৷ আপনি API এর সাথে ব্যক্তিগত Gmail অ্যাকাউন্ট ব্যবহার করতে পারবেন না। যদি গ্রাহকের অ্যাকাউন্টটি সংযুক্ত করতে সহায়তার প্রয়োজন হয়, তাহলে Google অ্যাকাউন্ট সংযুক্ত করুন থেকে নির্দেশাবলী পাঠান।

আপনি API কল করে একটি গ্রাহক তৈরি করার পরে, তারা তাদের কর্মীদের পোর্টাল অ্যাক্সেস পরিচালনা করে — আপনি API ব্যবহার করে আপনার গ্রাহকদের ব্যবহারকারীদের সম্পাদনা করতে পারবেন না। নীচের স্নিপেটটি দেখায় যে আপনি কীভাবে একজন গ্রাহক তৈরি করতে পারেন:

জাভা

// 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();

.নেট

// 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();

পাইথন

# 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 সরবরাহ করুন।

আপনি অন্য গ্রাহকের জন্য একই ডিভাইস দাবি করার আগে আপনাকে একটি গ্রাহকের ডিভাইস দাবিমুক্ত করতে হবে ( নীচে দেখুন )। একটি নতুন ডিভাইস তৈরি করার সময় দাবির পদ্ধতিগুলি IMEI বা MEID, অথবা সিরিয়াল নম্বর, প্রস্তুতকারকের নাম এবং মডেল এবং ChromeOS ডিভাইসের জন্য প্রত্যয়িত ডিভাইস আইডি সহ DeviceIdentifier ক্ষেত্রগুলিকে যাচাই করে

নীচের স্নিপেটটি দেখায় কিভাবে একটি ডিভাইস দাবি করতে হয়:

জাভা

// 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();

.নেট

// 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();

পাইথন

# 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 পদ্ধতিতে কল করুন।

বিক্রেতারা

আপনি আপনার ডিলার নেটওয়ার্কে রিসেলার অংশীদারদের প্রতিনিধিত্ব করতে বিক্রেতাদের ব্যবহার করতে পারেন, একটি বিশ্বব্যাপী রিসেলার নেটওয়ার্কের মধ্যে স্থানীয় অপারেটর বা আপনার পক্ষ থেকে ডিভাইস বিক্রি করে এমন কোনো সংস্থা। বিক্রেতারা আপনাকে আপনার ব্যবহারকারী, গ্রাহক এবং ডিভাইসগুলিকে আলাদা করতে সাহায্য করে:

  • আপনার তৈরি বিক্রেতারা আপনার জিরো-টাচ এনরোলমেন্ট অ্যাকাউন্ট বা একে অপরের অ্যাকাউন্ট দেখতে পাচ্ছেন না।
  • আপনি আপনার বিক্রেতাদের গ্রাহক এবং ডিভাইসগুলি দেখতে পারেন এবং আপনি বিক্রেতাদের ডিভাইসগুলি নিবন্ধনমুক্ত করতে পারেন৷ যাইহোক, আপনি আপনার বিক্রেতাদের গ্রাহকদের ডিভাইস বরাদ্দ করতে পারবেন না।

আপনার প্রতিষ্ঠানের জন্য বিক্রেতা তৈরি করতে পোর্টালটি ব্যবহার করুন — আপনি API ব্যবহার করতে পারবেন না। একটি নতুন বিক্রেতা তৈরি করতে আপনার অ্যাকাউন্টের ভূমিকা অবশ্যই মালিক হতে হবে৷ যদি আপনার প্রতিষ্ঠানে বিক্রেতা থাকে, তাহলে আপনি আপনার বিক্রেতাদের তালিকা করতে partners.vendors.list এবং আপনার বিক্রেতার গ্রাহকদের পেতে partners.vendors.customers.list কল করতে পারেন। নিম্নলিখিত উদাহরণটি বিক্রেতাদের গ্রাহকদের জন্য পরিষেবার শর্তাবলী দেখানো একটি প্রতিবেদন প্রিন্ট করতে এই উভয় পদ্ধতি ব্যবহার করে:

জাভা

// 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());
    }
  }
}

.নেট

// 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);
        }
    }
}

পাইথন

# 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 ক্ষেত্রের মান পরীক্ষা করুন।

আপনার সংস্থা একটি বিক্রেতা-দাবী করা ডিভাইস দাবিমুক্ত করতে পারে। অন্যান্য API কলগুলির জন্য যা ডিভাইসগুলিকে সংশোধন করে, আপনাকে পরীক্ষা করা উচিত যে API পদ্ধতিতে কল করার আগে আপনার সংস্থা ডিভাইসটি দাবি করেছে৷ নিম্নলিখিত উদাহরণ দেখায় কিভাবে আপনি এটি করতে পারেন:

জাভা

// 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;
    }
  }
}

.নেট

// 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;
        }
    }
}

পাইথন

# 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

দীর্ঘমেয়াদী ব্যাচ অপারেশন

এপিআই ডিভাইস পদ্ধতির অ্যাসিঙ্ক্রোনাস সংস্করণ অন্তর্ভুক্ত করে। এই পদ্ধতিগুলি অনেকগুলি ডিভাইসের ব্যাচ প্রক্রিয়াকরণের অনুমতি দেয়, যখন সিঙ্ক্রোনাস পদ্ধতিগুলি প্রতিটি API অনুরোধের জন্য একটি ডিভাইস প্রক্রিয়া করে। অ্যাসিঙ্ক্রোনাস পদ্ধতির নামের একটি Async প্রত্যয় রয়েছে, উদাহরণস্বরূপ claimAsync

অ্যাসিঙ্ক্রোনাস API পদ্ধতি প্রক্রিয়াকরণ সম্পূর্ণ হওয়ার আগে একটি ফলাফল প্রদান করে। অ্যাসিঙ্ক্রোনাস পদ্ধতিগুলি আপনার অ্যাপকে (বা টুল) আপনার ব্যবহারকারীদের জন্য প্রতিক্রিয়াশীল থাকতে সাহায্য করে যখন তারা একটি দীর্ঘ-চলমান অপারেশন সম্পূর্ণ হওয়ার জন্য অপেক্ষা করে। আপনার অ্যাপটি পর্যায়ক্রমে অপারেশনের স্থিতি পরীক্ষা করা উচিত।

অপারেশন

আপনি একটি দীর্ঘ-চলমান ব্যাচ অপারেশন ট্র্যাক করতে একটি Operation ব্যবহার করেন। একটি অ্যাসিঙ্ক্রোনাস পদ্ধতিতে একটি সফল কল প্রতিক্রিয়ায় অপারেশনের একটি রেফারেন্স প্রদান করে। updateMetadataAsync কল করার পরে নীচের JSON স্নিপেট একটি সাধারণ প্রতিক্রিয়া দেখায়:

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

প্রতিটি অপারেশনে পৃথক কাজের একটি তালিকা রয়েছে। অপারেশনে থাকা কাজের অবস্থা এবং ফলাফল সম্পর্কে তথ্য জানতে operations.get এ কল করুন। নিচের স্নিপেটটি দেখায় যে আপনি কীভাবে এটি করতে পারেন। আপনার নিজের অ্যাপে, আপনাকে যেকোনো ত্রুটি পরিচালনা করতে হবে।

জাভা

// 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();

.নেট

// 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();

পাইথন

# 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 অপারেশনে আপডেটের সংখ্যা দেখায়। যদি API কিছু আপডেট পার্স করতে না পারে তবে এটি আপনার অনুরোধে আপডেটের সংখ্যা থেকে ভিন্ন হতে পারে।

নীচের সরলীকৃত উদাহরণটি দেখায় যে কীভাবে একটি অ্যাপ ভোটদানের ব্যবধান সেট করতে অগ্রগতি মেটাডেটা ব্যবহার করতে পারে। আপনার অ্যাপে, ভোট দেওয়ার জন্য আপনার আরও পরিশীলিত টাস্ক রানার প্রয়োজন হতে পারে। আপনাকে ত্রুটি হ্যান্ডলিং যোগ করতে হবে।

জাভা

// 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);
  }
}

.নেট

// 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);
    }
}

পাইথন

# 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 API পদ্ধতিটি ডিভাইসের অনেক বড় তালিকা ফিরিয়ে দিতে পারে। প্রতিক্রিয়ার আকার কমাতে, এটি এবং অন্যান্য API পদ্ধতিগুলি (যেমন partners.devices.findByIdentifier ) পৃষ্ঠাযুক্ত ফলাফলগুলিকে সমর্থন করে৷ পৃষ্ঠাযুক্ত ফলাফলের সাথে, আপনার অ্যাপ্লিকেশন পুনরাবৃত্তিমূলকভাবে একটি সময়ে একটি পৃষ্ঠার বড় তালিকার অনুরোধ এবং প্রক্রিয়া করতে পারে।

API পদ্ধতিতে কল করার পরে, প্রতিক্রিয়াটি nextPageToken এর জন্য একটি মান অন্তর্ভুক্ত করে কিনা তা পরীক্ষা করে দেখুন। nextPageToken null না হলে, আপনার অ্যাপটি আবার পদ্ধতিতে কল করে ডিভাইসের অন্য পৃষ্ঠা আনতে এটি ব্যবহার করতে পারে। limit প্যারামিটারে ডিভাইসের সংখ্যার জন্য আপনাকে একটি উচ্চ সীমা সেট করতে হবে। nextPageToken null হলে, আপনার অ্যাপ শেষ পৃষ্ঠার জন্য অনুরোধ করেছে।

নীচের উদাহরণ পদ্ধতিটি দেখায় যে কীভাবে আপনার অ্যাপটি একবারে একটি পৃষ্ঠার ডিভাইসগুলির একটি তালিকা প্রিন্ট করতে পারে:

জাভা

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);

.নেট

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);

পাইথন

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);

পরবর্তী পদক্ষেপ

এখন যেহেতু আপনি জানেন কিভাবে API কাজ করে, Java , .NET , বা Python এর জন্য একটি কুইকস্টার্ট সহ উদাহরণগুলি চেষ্টা করে দেখুন।