Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Management API change Policy for device

I created 2 policies in my enterprise.

I would like to switch one device to the other policy without re-enroling it.

I tried to use android management enterprises devices.patch with following JSON

{ "policyName": "policy2" }

this link

When i execute this command i always get follwoing error Message:

{
 "error": {
  "code": 400,
  "message": "Illegal state transition from ACTIVE to DEVICE_STATE_UNSPECIFIED",
  "status": "INVALID_ARGUMENT"
 }
}

Does anybody know how to change policy for a device without wiping it?

like image 319
chriss Avatar asked Oct 23 '18 12:10

chriss


1 Answers

It is indeed possible to change the policy of a device without re-enrolling it, and you're not far from the solution.

You get this error because you implicitly attempt to change other fields of the Device resource (in particular the state field) by not setting them in the resource that you send in devices.patch.

You have two options:

  1. Set the updateMask in devices.patch to "policyName", to tell the API that you only want to change the policyName field.

  2. Call devices.get to get the current Device resource, and then send back the entire resource with only the policyName field changed in to devices.patch.

Using updateMask is preferable because it does an atomic read-modify-write.

like image 62
Fred Avatar answered Oct 24 '22 12:10

Fred