As mentioned in the google documents i have tested the following process

URL to quick start: https://colab.research.google.com/github/google/android-management-api-samples/blob/master/notebooks/quickstart.ipynb#scrollTo=pjHfDSb8BoBP

  1. Create Enterprise
  2. Create Policy
  3. Enroll the device

Then I have used the NODEJS API of Android Enterprises to develop the server based solution, which is working fine as per the documentation for all the functions such as get, create, delete the policy, devices, enterprises.

The issue i am facing is with the QR code generated from NODE application, when i scan the QR code generated from NODEJS application, the device got stuck at system update.

Following is my Policy update function

 router.post('/update/:id', async function(req, res) {
      const {title,policy_body,update_mask,enroll_url} = req.body;
      // here we are callng the android managment API to and then the response we will update to database
      const amApiBody  = {
        name: policy_body.name,
        updateMask:update_mask,
        requestBody:policy_body
      }
    const policy_update_response =  await  amApi.updatePolicy(amApiBody);
      const p =  await  policyModel.update(req.params.id,title,policy_update_response,enroll_url);
    res.json(p)
 });

AmAPI file

    this.updatePolicy = async function (body)
    { 
            const auth = new google.auth.GoogleAuth({
                scopes: ['https://www.googleapis.com/auth/androidmanagement'],
            });

            const authClient = await auth.getClient();
            google.options({auth: authClient});
            
            // Get the list of available policies
            const res = await androidmanagement.enterprises.policies.patch(body);
            console.log('requestFinalBody=',body);
            return res.data;

    }

Following is my policy data obtained by running above function

policy_create_response= {
  name: 'enterprises/LC019rjnor/policies/policy1',
  version: '14',
  applications: [
    {
      packageName: 'com.google.samples.apps.iosched',
      installType: 'FORCE_INSTALLED',
      autoUpdateMode: 'AUTO_UPDATE_HIGH_PRIORITY'
    },
    {
      packageName: 'com.dekaisheng.courier',
      installType: 'FORCE_INSTALLED',
      autoUpdateMode: 'AUTO_UPDATE_HIGH_PRIORITY'
    }
  ],
  keyguardDisabledFeatures: [ 'KEYGUARD_DISABLED_FEATURE_UNSPECIFIED' ],
  defaultPermissionPolicy: 'GRANT',
  uninstallAppsDisabled: true,
  keyguardDisabled: true,
  tetheringConfigDisabled: true,
  dataRoamingDisabled: true,
  networkEscapeHatchEnabled: true,
  bluetoothDisabled: true,
  debuggingFeaturesAllowed: true,
  funDisabled: true,
  kioskCustomLauncherEnabled: true
}

Note i have exported the variable to the terminal as follows before running the app, the auth.json is the service account credential file.

export GOOGLE_APPLICATION_CREDENTIALS="/Users/Mac/Projects/wajid/mdm/server/env/auth.json"  

Thanks for the help in advance

1

There are 1 best solutions below

0
On

I figured out that in nodeJS API I was passing wrong property name of Policy value in the request body.

Code before fix

        parent: this.getParent(policyName),
        requestBody:{
            “name”: “my_policy"
        }

Code after fix

 parent: this.getParent(policyName),
        requestBody:{
            "policyName”: “my_policy"
        }