This document introduces the API and explains the patterns. If you want to
explore the API yourself, see Get started.

API concepts

Customers and devices are the core resources you use in the API. To create
customers, call create. You can create devices
using the claim API methods (see below). Your organization can also
create customers and devices using the zero-touch enrollment portal.

Customer

Companies that your organization sell devices to. Customers have a name and
an ID. Use a customer when you want to claim or find their devices. To learn
more, see Customer.

Device

A zero-touch enrollment-capable Android device your organization sells to a
customer. Devices have hardware IDs, metadata, and customer claims. Devices are
central to the API, so you use them in almost all methods. To learn more, see
Device.

DeviceIdentifier

Encapsulates hardware IDs, such as IMEI or MEID, to identify a manufactured
device. Use a DeviceIdentifier to target the device you want to find, update,
or claim. To learn more, read Identifiers.

To list all the API methods and resources your app can use, see the
API Reference.

Create customers

You can call the create API method to create
customer accounts for zero-touch enrollment. Because your customers see the
company name in their zero-touch enrollment portal, your app's user should
confirm that it's correct. You can't edit a customer's name after you create
the customer.

You need to include at least one corporate email address, associated with a
Google Account, to be the owner. You can't use personal Gmail accounts with the
API. If the customer needs help associating the account, send the instructions
from Associate a Google Account.

Note: The API returns an error when one or more of the email addresses isn't
associated with a Google Account. When this happens, ask your user to check
that there's a Google Account
for each email address. Google doesn't provide an API to check if an email
address is associated with a Google Account.

After you create a customer by calling the API, they manage their employees'
portal access—you can't edit your customers' users using the API. The Python
snippet below shows how you might create a customer:

# Provide the customer data as a Company type
company = {'companyName':'XYZ Corp', \
'ownerEmails':['liz@example.com', 'darcy@example.com'], \
'adminEmails':['jane@example.com']}
# Set the reseller ID as the partner
parent_resource = 'partners/{0}'.format(MY_PARTNER_ID)
# Create the customer using the values in the company
results = provisioning.partners().customers().create(parent=parent_resource,
body={'customer':company}).execute()

The API doesn't notify your customer that they have access. Typically, your
organization contacts the customer to tell them about the portal. You might want
to send them a link to the portal so that they can manage their users. To learn
more about the owner and admin roles for employees of your customer, read
Portal users.

Claim devices for customers

After your customers purchase devices, they'll want to configure provisioning
settings for these devices in their account. Claiming a device adds the device
to zero-touch enrollment and shows the device in the customer's view of the
portal.

A device's provisioning record has a section for zero-touch enrollment. You
assign the device by claiming the record's zero-touch enrollment section for a
customer. Call the partners.devices.claim or
partners.devices.claimAsync methods with the
customer as an argument. Always supply SECTION_TYPE_ZERO_TOUCH as a value for
sectionType.

You'll need to unclaim (see below) a customer's device before you can
claim the same device for a different customer. The claim methods
validate the DeviceIdentifier fields, including the IMEI
number and manufacturer name, when
creating a new device.

Unclaiming devices

Your organization can unclaim a device from a customer. Unclaiming a device
removes it from zero-touch enrollment. A reseller might unclaim a device that
they want migrated to another account, returned, or that was mistakenly claimed.
Call the method partners.devices.unclaim or
partners.devices.unclaimAsync to unclaim a
device from a customer.

Caution: Consider prompting your app's user to confirm that they have the
correct device before calling unclaim APIs. Unclaiming a device removes the
customer's provisioning setup and the device becomes unmanaged after a factory
reset.

Long-running batch tasks

The API includes asynchronous versions of the device methods.
These methods allow batch processing of many devices, while the synchronous
methods process one device for each API request. The asynchronous method names
have an Async suffix, for example claimAsync.

Asynchronous API methods return a result before the task is complete.
Asynchronous methods help your app (or tool) remain responsive for your users
while they wait for a long-running task to complete. Your app should check the
status of the task periodically.

Operations

You use an Operation to track a long-running task. A successful
asynchronous method call returns a reference to the operation in the response.
The JSON snippet below shows a typical response after calling
updateMetadataAsync:

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

Call operations.get to find out information about the status
and results of the task. The Python snippet below shows how you might do this.
In your own app, you'll need to handle any errors.

To find out if an operation finished, check the operation for a done field
with a value of true. If done is missing or false, the operation is still
running.

Responses

After an operation finishes, the API updates the operation with the result—even
if all or none of the items are successful. The response field is a
DevicesLongRunningOperationResponse
object detailing the processing of each item in the task.

Inspect the successCount field to efficiently find out if any items failed and
avoid iterating through large result lists. The perDeviceStatus field of
DevicesLongRunningOperationResponse is a list of
OperationPerDevice instances detailing each item in the
task. The list order matches the items in the original request.

Each OperationPerDevice item contains a result field and a reminder summary
of the request received by the server. Check if the item succeeded or failed
using the result field.

The JSON snippet below shows part of a typical response from an operation after
a call to updateMetadataAsync:

Track progress

If your app needs to track progress of a task, you should periodically refetch
the operation. The metadata field contains a
DevicesLongRunningOperationMetadata
instance to help your app check the latest progress of a running operation. Use
the fields of DevicesLongRunningOperationMetadata listed in the following
table to track the operation's progress.

Field

Typical use

processingStatus

Changes from BATCH_PROCESS_PENDING to BATCH_PROCESS_IN_PROGRESS, and then to BATCH_PROCESS_PROCESSED as the operation progresses.

progress

The percentage of updates processed. Your app can use this to estimate a finish time. Because the progress value can be 100 while the operation is finishing up, check the done field of an operation to know if it finished and has a result.

devicesCount

Shows the number of updates in the operation. This might be different from the number of updates in your request if the API can't parse some of the updates.

The simplified Python example below shows how an app might use the progress
metadata to set polling intervals. In your app, you might need a more
sophisticated task runner for polling. You'll also need to add error handling.