1

I'm trying to reset the lock code of my device through android management API but it seems that RESET_PASSWORD doesn't do anything. The endpoint is https://androidmanagement.googleapis.com/v1/enterprises/entrepriseID/devices/deviceID:issueCommand and my payload looks like this

{
    "type": "RESET_PASSWORD" ,
    "duration": "600s",
    "newPassword":"1234",
    "resetPasswordFlags":["LOCK_NOW"]
}
Gab
  • 11
  • 1

2 Answers2

1

Does anyone find any solution ? I have the same problem with this command :

I find the command in the documentation.

When i execute this CURL, it answer me 200 OK.

curl --location --request POST 'https://androidmanagement.googleapis.com/v1/enterprises/<enterprise>/devices/<device_id>:issueCommand' \
--header 'content-type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data-raw '{
    "type": "RESET_PASSWORD",
    "duration": "600s"
}'
{
    "name": "enterprises/<enterprise>/devices/<device_id>/operations/<operation_id>",
    "metadata": {
        "@type": "type.googleapis.com/google.android.devicemanagement.v1.Command",
        "type": "RESET_PASSWORD",
        "createTime": "2022-05-03T09:34:15.913Z",
        "duration": "600s",
        "userName": "enterprises/<enterprise>/users/<user_id>"
    }
}

But, when i try to get the health of the operation, it answer to me an error:

curl --location --request GET 'https://androidmanagement.googleapis.com/v1/enterprises/<enterprise>/devices/<device_id>/operations/<operation_id>' \
--header 'content-type: application/json' \
--header 'Authorization: Bearer <TOKEN>'

Answer (200 OK):

{
    "name": "enterprises/<enterprise>/devices/<device_id>/operations/<operation_id>",
    "metadata": {
        "@type": "type.googleapis.com/google.android.devicemanagement.v1.Command",
        "type": "RESET_PASSWORD",
        "createTime": "2022-05-03T09:34:15.913Z",
        "duration": "600s",
        "errorCode": "INVALID_VALUE",
        "userName": "enterprises/<enterprise>/users/<user_id>"
    },
    "done": true,
    "error": {
        "code": 3
    }
}

i don't know which invalid value i put into the params..

More, the LOCK or REBOOT command work correctly without any error for the same device.

Sincerely.

Adrien.

  • The “INVALID_VALUE” in the `errorCode` may mean your new password does not meet the password policy requirement you set in your policy. When that happens, the device does not lock and the password is not changed. Make sure the value for the new password meets the password requirements on the policy.. You can check [here](https://developers.google.com/android/management/reference/rest/v1/PasswordRequirements#PasswordQuality) for the PasswordPolicies of Android Management API. – rsiason Jun 28 '22 at 13:53
0

I tried to recreate the scenario using the same settings that you are using and I was able to reset my password and change it to the new password.

device_name = enterprise_name + '/devices/deviceId'
 
device_json = '''
{
  "duration": "600s",
  "type": "RESET_PASSWORD",
  "newPassword": "12345",
  "resetPasswordFlags": [
    "LOCK_NOW"
  ]
}
'''
 
androidmanagement.enterprises().devices().issueCommand(
    name=device_name,
    body=json.loads(device_json)
).execute()

This API seems to be working properly in my end. For this API to work properly, please make sure the newPassword value meets any passwordRequirements you have set in the policy. Also, you can check the device if it receives the command as it should lock its screen automatically upon receiving the command.

You can also try using other commands to ensure that the issue is not in your device or connection.

rsiason
  • 156
  • 5
  • The LOCK et dans the REBOOT command are working without any problem. Are we talking about the lock code of the device ? The pin code that you have to enter to unlock the device every time you use it ? Because, nothing happens on the phone when I do the RESET_PASSWORD action whereas everything is working fine with the other actions. Am I missing something ? – Gab Apr 26 '22 at 14:20