Metadati del dispositivo

In qualità di rivenditore, puoi associare metadati, ad esempio un numero di telefono o un numero di ordine di acquisto, a ogni dispositivo. Puoi associare i metadati chiamando l'API o caricando un file CSV nel portale della registrazione zero-touch. La tabella 1 mostra chi può associare e visualizzare i metadati:

Tabella 1. Autorizzazioni metadati

Attività Resellers (Rivenditori) Clienti
Associa i metadati chiamando l'API
Associa i metadati caricando un file CSV sul portale della registrazione zero-touch
Visualizzare i metadati del dispositivo nei risultati delle chiamate API
Visualizzare i metadati del dispositivo nel portale della registrazione zero-touch

Assegnare metadati

Per associare i metadati a ciascun dispositivo, chiama il metodo partners.devices.metadata. Puoi aggiungere numeri di telefono e numeri d'ordine per i dispositivi Android utilizzando le chiavi indicate nella tabella 2 che segue:

Tabella 2. Chiavi dei metadati per i dispositivi Android

Dati Chiave Tipo di valore Esempio
Numero di telefono phonenumber Stringa +39 338 5550100
Numero ordine ordernumber Stringa GOOG#123/ABC-123456

Entrambi i valori dei metadati sono stringhe in formato libero, pertanto puoi utilizzare un formato adatto alla tua organizzazione.

Per i dispositivi ChromeOS, puoi utilizzare i tasti della tabella 3 riportata di seguito:

Tabella 3. Chiavi dei metadati per i dispositivi ChromeOS

Dati Chiave Tipo di valore Esempio
Numero ordine ordernumber Stringa GOOG#123/ABC-123456

Per assegnare i metadati durante la creazione dei dispositivi, includili quando chiami claimAsync. L'esempio seguente mostra l'impostazione di un numero di telefono e di un numero d'ordine per il dispositivo esistente 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()

Gli argomenti dei metadati sostituiscono i valori dei metadati esistenti per la stessa chiave.

Elimina metadati

Puoi eliminare i metadati dai dispositivi. Passa stringhe vuote per i valori dei metadati che vuoi eliminare. L'esempio seguente mostra come eliminare il numero di telefono:

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...