We are developing an emm console. Currently we are facing one issue with device data. How to get the unique id from the device provisioned via enrollment token using Android management api.
A is an enterprise, we enrolled the mobile device to the enterprise A. After that some policies are updated and it works fine. Later we factory resetting the device. Now the same device is enrolled to enterprise B. The mobile device state is active in both enterprise A and enterprise B. We don't know how to overcome this issue?
My suggestion: In our local database we planned to keep the id for device and enrollment time. To form the unique id of the device which field we want to compare or do we have any other options to compare and get the unique id
I may have misinterpreted the question(s), but what I did is pass extra data whenever enrolling a device - in my case, we are using devices as kiosk apps and they are tied to database 'terminal' entries that are already recorded in our server database. Whenever a device is enrolled, you can use an identifier system that you pass as the additional data. In my case, it was the id field of the database entry. Since the database was tied to unique fields, we could always query for the specific device ID based on the DB. So in my case, some facility would have 5 devices with unique id fields and names, even, so I could query devices.list and parse for the additional data where === my DB ids, and then update the database with the current, linked device ID.
For creating enrollment tokens: https://developers.google.com/android/management/reference/rest/v1/enterprises.enrollmentTokens
You set the 'additionalData' field when enrolling, then when calling devices.list or possibly devices.get, you can look for that ID field - it's under 'enrollmentTokenData' if using 'additionalData.' You could also set an account identifier tied to a user and use that as an ID. So during enrollment, you set 'user.accountIdentifier,' and then look for the same when doing devices.list/get.
API instructions on devices:
https://developers.google.com/android/management/reference/rest/v1/enterprises.devices
Again, this may not have been your issue, but it's how I personally kept up with the device IDs that are currently tied to my DB 'terminals.'
The main caveat to this is making sure I don't have duplicate devices enrolled (possibly like you have mentioned with Enterprise A/B, apologize if misinterpreted). What I've done is setup my admin console so that you can call devices.delete. This does a factory reset AND deletes the device item from the Mgmt. API. If you manually do a factory reset on the device, then the device record STILL RESIDES in the Mgmt. API, which doesn't seem ideal. So we just make sure to always use the Mgmt API to delete devices, so as not to have duplicates.