0

I'm using Google Scripts to maintain a list of Chrome devices on our domain.

I'm using the AdminDirectory.Chromeosdevices.list method to get all the information I require and write it to a sheet.

I am then trying to write a script to write information to the annotatedLocation and annotatedAssetId fields using the Chromeosdevices.update method.

My problem: I receive a phrase error using the following, from looking at the suggestion: update(resource, customerId, deviceId, optionalArgs) I don't seem to have a 'resource', I cannot seem to find any way to get this value.

Any suggestions as to how I can get the resource??

var options = {
  "annotatedAssetId": (data[i][13] == "") ? data[i][3] : data[i][13],
  "annotatedLocation": (data[i][14] == "") ? data[i][4] : data[i][14],
  "notes": (data[i][15] == "") ? data[i][7] : data[i][15],
  "orgUnitPath": (data[i][16] == "") ? data[i][15] : data[i][16]
}
 var device = AdminDirectory.Chromeosdevices.update(data[i][11],"my_customer", data[i][10], options)

Thank you

James D
  • 3,102
  • 1
  • 11
  • 21

3 Answers3

1

I think you're referring to this line:

In the request body, supply a Chromeosdevices resource with the following properties:

resource is referring to Chromeosdevices resource.

{
  "kind": "admin#directory#chromeosdevice",
  "etag": etag,
  "deviceId": string,
  "serialNumber": string,
  "status": string,
  "lastSync": datetime,
  "supportEndDate": datetime,
  "annotatedUser": string,
  "annotatedLocation": string,
  "annotatedAssetId": string,
  "notes": string,
  "model": string,
  "meid": string,
  "orderNumber": string,
  "willAutoRenew": boolean,
  "osVersion": string,
  "platformVersion": string,
  "firmwareVersion": string,
  "macAddress": string,
  "bootMode": string,
  "lastEnrollmentTime": datetime,
  "orgUnitPath": string,
  "recentUsers": [
    {
      "type": string,
      "email": string
    }
  ],
  "ethernetMacAddress": string,
  "activeTimeRanges": [
    {
      "date": date,
      "activeTime": integer
    }
  ]
}

Click the link for more info.

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
  • Thanks noogui but just to clarify (as I'm not very experienced with app script), I can 'get' this resource using the get method with the customer ID and device ID and then pass it back into the resource parameter of update along with my options as shown above? – James D Jun 04 '17 at 08:26
  • I tested what I said above and it didn't work. I still can't figure it out. Could you provide an example? – James D Jun 04 '17 at 11:19
  • Sorry didnt mention that this is using [Directory API](https://developers.google.com/admin-sdk/directory/v1/reference/chromeosdevices/list), was only referring to the 'resource' keyword – ReyAnthonyRenacia Jun 04 '17 at 14:50
  • So is it possible to retrieve a 'resource' for the resource parameter in `update(resource, customerId, deviceId, optionalArgs)` using GAS? – James D Jun 04 '17 at 15:20
0

This is working for me. Hopefully it helps you out.

function getDeviceID(assetID) {
    //Find chrome device
    var assetTag = 'asset_id:' + assetID;
    var chromebookDevices = (AdminDirectory.Chromeosdevices.list("my_customer", {
    query: assetTag
    }));

    //Change values
    chromebookDevices.chromeosdevices[0].annotatedUser = 'New name';
    //Push changes
    var updatedChromebook =(AdminDirectory.Chromeosdevices.update(chromebookDevices.chromeosdevices[0], "my_customer", chromebookDevices.chromeosdevices[0].deviceId));
}
Jfran
  • 1
0

Maybe this has been figured out already, but the first argument is the JSON object noogui refers to. Use the method on adminDirectory.Chromeosdevices.get() to first retrieve the object. Modify this object as needed, then use adminDirectory.Chromeosdevices.update() with that modified object as the first argument.

Jess
  • 1