Device metadata

As a reseller you can associate metadata, such as a telephone number or a purchase order number, with each device. You can associate metadata by calling the API or by uploading a CSV file in the zero-touch portal. Table 1 shows who can associate and view metadata:

Table 1. Metadata permissions

Task Resellers Customers
Associate metadata by calling the API
Associate metadata by uploading a CSV file to the zero-touch portal
View device metadata in the results of API calls
View device metadata in the zero-touch portal

Assign metadata

To associate metadata with each device, call the partners.devices.metadata method. You can add telephone and order numbers for your Android devices using keys from the table 2 below:

Table 2. Metadata keys for Android devices

Data Key Value type Example
Telephone number phonenumber String +1 (800) 555-0100
Order number ordernumber String GOOG#123/ABC-123456

Both metadata values are free-form strings, so you can use a format that makes sense for your organization.

For ChromeOS devices, you can use the keys from table 3 below:

Table 3. Metadata keys for ChromeOS devices

Data Key Value type Example
Order number ordernumber String GOOG#123/ABC-123456

To assign metadata as you create devices, include the metadata when calling claimAsync. The example below shows setting a telephone number and order number for the existing device TARGET_DEVICE_ID:

Java

// Allowed metadata dictionary keys.
private static String METADATA_KEY_PHONE_NUMBER = "phonenumber";
private static String METADATA_KEY_ORDER_NUMBER = "ordernumber";

// ...
// Create the metadata record with the values.
DeviceMetadata metadata = new DeviceMetadata();
Map<String,String> entries = new HashMap<String, String>();
entries.put(METADATA_KEY_ORDER_NUMBER, "GOOG123/ABC-#123456");
entries.put(METADATA_KEY_PHONE_NUMBER, "+1 (800) 555-0100");
metadata.setEntries(entries);

// Set the metadata values on the target device.
UpdateDeviceMetadataRequest body = new UpdateDeviceMetadataRequest();
body.setDeviceMetadata(metadata);

DeviceMetadata response = service
        .partners()
        .devices()
        .metadata(PARTNER_ID, targetDeviceId, body)
        .execute();

.NET

// Allowed metadata dictionary keys.
private static string MetadataKeyPhoneNumber = "phonenumber";
private static string MetadataKeyOrderNumber = "ordernumber";

// ...
// Create the metadata record with the values.
DeviceMetadata metadata = new DeviceMetadata
{
    Entries = new Dictionary<string, string> {
        {MetadataKeyOrderNumber, "GOOG123/ABC-#123456"},
        {MetadataKeyPhoneNumber, "+1 (800) 555-0100"}
    }
};

// Set the metadata values on the target device.
UpdateDeviceMetadataRequest body = new UpdateDeviceMetadataRequest
{
    DeviceMetadata = metadata
};
var request = service.Partners.Devices.Metadata(body, PartnerId, targetDeviceId);
var results = request.Execute();

Python

# Allowed metadata dictionary keys.
METADATA_KEY_ENTRIES = "entries";
METADATA_KEY_PHONE_NUMBER = "phonenumber";
METADATA_KEY_ORDER_NUMBER = "ordernumber";

# ...
# Create the record with values.
new_metadata = {METADATA_KEY_ENTRIES:{ \
    METADATA_KEY_PHONE_NUMBER:'+1 (800) 555-0100', \
    METADATA_KEY_ORDER_NUMBER:'GOOG123/ABC-#123456'}}

# Set the metadata values on the target device.
response = service.partners().devices().metadata(
    metadataOwnerId=PARTNER_ID,
    deviceId=target_device_id,
    body={'deviceMetadata':new_metadata}).execute()

Your metadata arguments replace existing metadata values for the same key.

Delete metadata

You can delete your metadata from devices. Pass empty strings for metadata values you want to delete. The example below shows how to delete the telephone number:

Java

// Create the metadata record with the values.
DeviceMetadata metadata = new DeviceMetadata();
Map<String,String> entries = new HashMap<String, String>();
entries.put(METADATA_KEY_PHONE_NUMBER, "");
metadata.setEntries(entries);

// Call partners().devices().metadata() to remove the phone metadata from the device...

.NET

// Create the metadata record with empty values.
DeviceMetadata metadata = new DeviceMetadata
{
    Entries = new Dictionary<string, string> {
        {MetadataKeyPhoneNumber, ""}
    }
};

// Call Partners.Devices.Metadata to remove the phone metadata from the device...

Python

# Create the metadata record with empty values.
metadata_to_remove = {METADATA_KEY_ENTRIES: {METADATA_KEY_PHONE_NUMBER:''}}

# Call partners().devices().metadata() to remove the phone number
# metadata from the device...