1

We have been using Android Management APIs to enroll devices in an enterprise and provide restricted environment to our users. We have a requirement where we need to bulk update all the devices by making a patch request using this API: https://developers.google.com/android/management/reference/rest/v1/enterprises.devices/patch

What I am looking for is that instead of sending requests one by one in an arbitrary fashion, is there any way I can send bulk requests and receive a response when all the devices are updated?

Note: I am already aware of how to do it one by one.

Help appreciated, thanks.

Zubair Rehman
  • 2,335
  • 2
  • 20
  • 25

3 Answers3

1

Use the AndroidManagement.batch() API to queue several requests for execution and reduce the connections your client makes. The now deprecated Google EMM API documentation has more information about this.

Here's a pseudo example on how to create a batch request, queue a device patch call and execute the request thereafter.

AndroidManagement amapi;
var batchRequest = amapi.batch();
amapi.enterprises().devices().patch(deviceName, content).queue(batchRequest, new JsonBatchCallback<>() {

                    @Override
                    public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException {
                    }

                    @Override
                    public void onSuccess(com.google.api.services.androidmanagement.v1.model.Device device, HttpHeaders responseHeaders) throws IOException {
                        updateDevice(device);
                    }
                });

// queue another device patch request...

// execute all queued requests
batchRequest.execute();

Please note that if you want to do a bulk update in order to save on the API usage limit, this will not help you. All requests in your batch will be counted separately when it comes to limits. There is no way around this.

petarov
  • 131
  • 2
  • 12
0

Can you give more context about what you are trying to achieve? Perhaps what you want to do can be achieved with a policy. For example, to install an app on multiple devices, you could apply the same policy to those devices, and then add these lines to the policy:

"applications": [
  {
    "packageName": "com.google.samples.apps.iosched",
    "installType": "FORCE_INSTALLED"
  }
]

Regarding batch requests, here’s a sample code on how you can do batch requests in Android Management API.

def list_devices(request_id, response, exception):
    """Do something with the devices list response."""
    if exception is not None:
      # Do something with the exception.
      pass
    else:
      # Do something with the response.
      pass

get_device1 = androidmanagement.enterprises().devices().get(name=deviceName)
get_device2 = androidmanagement.enterprises().devices().get(name=deviceName)

batch = androidmanagement.new_batch_http_request();
batch.add(get_device1, list_devices)
batch.add(get_device2, list_devices)
batch.execute()

You may also check this link for more details about new_batch_http_request.

Dave Paurillo
  • 231
  • 1
  • 12
0

"You can use the batch() call on AndroidEnterprise and execute bulk requests by calling BatchRequest.execute(). Please note, you are limited to 1000 calls in a single batch request, so if you need to make more calls than that, use multiple batch requests.

Here's the format you can refer to: EMM API batch format. Along with an example: EMM API batch example."