How to automate Android enrollment and policy through an EMM API
An EMM API lets your own systems do what an admin does in the console: create enrollment tokens, assign policies, send commands and read device state. That is enough to enroll devices from a provisioning line, keep policy in version control, and react to events without a person watching a dashboard. The API you call is almost always your EMM vendor's. Google's Android Management API (AMAPI) sits underneath it and is reserved for EMM developers.
Key facts
- An EMM API lets your own systems create enrollment tokens, assign policies, send commands and read device state.
- You call your EMM vendor's API. Google reserves the Android Management API for commercial EMM developers, Device Trust providers and OEMs.
- An AMAPI enrollment token expires after one hour unless you set a duration.
- A device enrolled without a valid policy is quarantined. If none is linked within five minutes, enrollment fails and the device is factory reset.
- An Android policy is a JSON document, so it can be stored in Git, reviewed, validated in CI and deployed through the API.
- An AMAPI command expires after ten minutes by default. AMAPI allows 1,000 queries per 100 seconds for a project.
Which API do you call to automate Android device management?
| API | Who can use it | What it is for |
|---|---|---|
| Your EMM's API | Customers of that EMM | Devices, policies, enrollment, commands and events |
| Android Management API | Commercial EMM developers, Device Trust providers and OEMs, with Google's approval | The layer an EMM is built on |
| Zero-touch customer API | Organizations and EMMs with a zero-touch account | Create configurations, apply them to devices, deregister devices |
| Knox cloud APIs | Samsung Knox customers and partners | Bring Knox Mobile Enrollment into your own portal |
AMAPI's model is still worth knowing, because most EMM APIs mirror it. There is an enterprise, which owns policies and devices. An enrollment token joins a device to a policy. A command acts on one device.
How do you automate Android device enrollment?
There are three patterns. Most fleets use the first two together.
A token for each batch
Create an enrollment token for each shipment or site. It names the policy, sets an expiry and carries a tag. Print its QR code on the packing slip. In AMAPI terms, the request looks like this:
POST /v1/enterprises/{enterpriseId}/enrollmentTokens
{
"policyName": "enterprises/{enterpriseId}/policies/kiosk-store",
"duration": "2592000s",
"allowPersonalUsage": "PERSONAL_USAGE_DISALLOWED_USERLESS",
"additionalData": "site=store-0142"
}
Three details matter. AMAPI tokens expire after one hour unless you set a duration. A dedicated device needs the userless setting shown here. And the tag comes back on the enrolled device, so you can tell which batch it came from.
Enroll at first boot, then assign
With zero-touch or Knox Mobile Enrollment, devices enroll at first boot using a long-lived token. Your automation receives the enrollment event, looks up the serial number in your asset system, and moves the device to its final policy.
Always attach a working policy to the token itself. Google's provisioning guide warns that a device enrolled without a valid policy is quarantined. If no policy is linked within five minutes, enrollment fails and the device is factory reset. Automation should refine the policy, not supply the only one.
The two enrollment services are compared in Knox Mobile Enrollment vs zero-touch enrollment.
Sign-in at enrollment
For devices assigned to a person, the enrollment flow can open your sign-in page. Your endpoint authenticates the user and returns a token for the right policy. Google notes that this method does not suit dedicated devices.
How do you manage Android policy as code?
An Android policy is a JSON document. That makes it a good fit for version control.
- Store each policy as a file in a repository.
- Review every change as a pull request, with a second person reading it.
- Validate in CI. Check the schema, then your own rules. For example: every enterprise Wi-Fi network has a server domain set, and every kiosk policy has an update window.
- Deploy through the API on merge. In AMAPI, each update raises the policy's version number, and devices report the version they have applied.
- Stage it. Apply the change to a pilot policy first, then promote it.
- Detect drift. Compare what devices report, including non-compliance details, with what the repository says.
- Roll back by reverting the commit.
Keep secrets out of the repository. Wi-Fi passphrases and certificates belong in a secret store, injected at deploy time.
How do you react to enrollment and device events?
AMAPI publishes notifications through Google Cloud Pub/Sub. The types include ENROLLMENT, STATUS_REPORT, COMMAND and USAGE_LOGS. EMM vendors usually surface these to customers as webhooks.
Typical uses are assigning a policy on enrollment, opening a ticket when a device becomes non-compliant, and confirming that a command finished. Treat an event as a hint. Delivery time varies and events can repeat, so read the device's current state from the API before acting.
How do remote commands behave through an API?
Commands are asynchronous. You issue one, receive an operation, and the device completes it later or not at all. In AMAPI, a command expires after ten minutes by default. Set a longer duration for devices that may be offline, and check the result before assuming success.
Which guardrails does automation need?
- Keep keys server-side, in a secret manager, with an expiry and a rotation routine.
- Know what a key can do. If keys cannot be scoped, treat every key as an administrator.
- Respect rate limits. Back off when the API answers 429, for as long as
Retry-Aftersays. AMAPI itself allows 1,000 queries per 100 seconds for a project. - Make runs repeatable. Creating a token twice makes two tokens. Tag what you create, and check before creating again.
- Cap destructive actions. A script that can wipe devices needs a maximum per run and a human approval step.
- Separate staging from production. Test against a separate enterprise.
- Log request IDs. Support teams ask for them first.
AI agents need the same discipline. Google previewed a Model Context Protocol integration for AMAPI in February 2026 with read-only tools. Read-only is a sensible default for any agent.
What does the AndroidNexus API look like?
The AndroidNexus REST API is part of the Enterprise plan. Its base URL is https://api.androidnexus.ai/api/v1, and requests carry an API key as a bearer token.
# List devices
curl "https://api.androidnexus.ai/api/v1/devices?page=1&per_page=20" \
-H "Authorization: Bearer $ANDROIDNEXUS_API_KEY"
# Lock one device
curl -X POST "https://api.androidnexus.ai/api/v1/devices/$DEVICE_ID/commands" \
-H "Authorization: Bearer $ANDROIDNEXUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"command_type": "lock_device"}'
Per the API introduction, each key is limited to 1,000 requests a minute, list endpoints page at up to 100 items, and every response carries a request ID. Every key has full administrator authority over the enterprise, so keys stay on servers. The reference also covers policies, enrollment, webhooks, private apps and rollouts, and audit logs.
Frequently asked questions
Can I call the Android Management API directly for my own fleet?
No. Google restricts AMAPI to commercial EMM developers, Device Trust providers and OEMs, and it does not permit tools built only for in-house use. You automate through your EMM vendor's API instead.
What can be automated through an EMM API?
Enrollment tokens and QR codes, policy creation and updates, moving devices between policies, commands such as lock, reboot and wipe, app assignments, and device inventory. The exact list depends on the vendor.
Do I need zero-touch to automate enrollment?
No. Tokens and QR codes can be generated by API and work on any supported device. Zero-touch and Knox Mobile Enrollment remove the scanning step, so the device enrolls at first boot.
How long does an enrollment token last?
In AMAPI, one hour by default. A duration can be set, up to roughly 10,000 years. Your EMM may apply its own defaults, so check before you print a QR code that has to work next month.
How do I keep Android policy in Git?
Store each policy as a JSON file, review changes as pull requests, validate them in CI, and deploy through the API on merge. Compare the policy version devices report with the version in the repository to catch drift.
Is there a webhook when a device enrolls?
At the AMAPI level, an enrollment notification arrives through Google Cloud Pub/Sub. EMM vendors generally expose that to customers as a webhook or event feed. Check your vendor's reference.
Can an AI agent manage devices through the API?
Technically, yes, with the same key any script would use. Give an agent read-only access first. Treat write access like any privileged automation, with caps and human approval for destructive actions.
What happens if a device enrolls without a policy?
Google's provisioning guide says the device is quarantined. If no valid policy is linked within five minutes, enrollment fails and the device is factory reset. Attach a working policy to the enrollment token, and let automation refine it afterward.
What are the Android Management API rate limits?
AMAPI allows 1,000 queries per 100 seconds for a project. That limit applies to the EMM vendor's project. Your vendor's own API sets the limit you work with, so read its reference and back off when it answers 429.
Sources
- Provision a device, Android Management API guide
- Permissible usage, Android Management API
- Set up Pub/Sub notifications, Android Management API guide
- enterprises.devices.issueCommand, Android Management API reference
- Android Management API release notes, Google
- Zero-touch customer API: how it works, Google
- Knox Mobile Enrollment FAQ, Samsung Knox
- AndroidNexus API introduction, AndroidNexus docs