Reputation: 91
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" }
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?
Upvotes: 8
Views: 2031
Reputation: 346
If you try this from management api test site then add updateMask as "policyName"
Upvotes: 0
Reputation: 91
i foudn a solution for my problem:
{ "policyName": "policy2" , "state":"active"}
Upvotes: 1
Reputation: 634
As Fred mentioned, updateMask is the preferred way to go. Here's an example of how to use the updateMask approach in the Google colab
swap_result = androidmanagement.enterprises().devices().patch(
name='enterprises/ENTERPRISE_NAME/devices/DEVICE_ID', updateMask='policyName', body={ "policyName": "enterprises/ENTERPRISE_NAME/policies/NEW_POLICY_NAME"}).execute()
Upvotes: 3
Reputation: 2251
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:
Set the updateMask
in devices.patch
to "policyName"
, to tell the API that you only want to change the policyName
field.
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.
Upvotes: 8