Clear app data on a schedule — Esper Commands API with a WINDOW schedule
Android
When shared devices are not logged out between shifts, stale session data, cached credentials, and leftover user state persist across workers. Automating CLEAR_APP_DATA via the Esper Commands API on a recurring schedule wipes this data at a defined window without requiring any manual action from the device user.
Why this happens
Android apps store session tokens, cached files, and user preferences in local app storage. Unless a user explicitly signs out or the app is designed to clear its own state, that data remains on the device indefinitely. Esper does not automatically clear app data between sessions — a scheduled command is required to trigger it on your cadence.
Before you begin
- You have access to the Esper Console and a valid API bearer token.
- You know the package name of each app whose data you want to clear (for example,
com.example.app). - You can create and manage a cron job on your own infrastructure.
- The target device must be online during the scheduled execution window.
Step-by-step setup
- Find the device UUID. In the Esper Console, go to Devices & Groups → [Device Name] → Device Details and copy the device UUID. This identifier is required in the API request body.
- Retrieve your API bearer token. In the Esper Console, go to API Key Management, then generate a new token or copy an existing one. Store this token securely — it authorises all API requests made on behalf of your tenant.
-
Submit the CLEAR_APP_DATA command. Send a
POSTrequest to the Commands API endpoint below, replacing all placeholder values with your own:POST https://{your-tenant}.esper.cloud/api/commands/v0/commands/ Authorization: Bearer {your_api_token} Content-Type: application/json { "command_type": "DEVICE", "devices": ["your-device-uuid"], "command": "CLEAR_APP_DATA", "command_args": { "package_name": "com.example.app" }, "schedule": "WINDOW", "schedule_args": { "name": "Shift Change - Clear App Data", "start_datetime": "2024-05-20T23:00:00Z", "end_datetime": "2024-05-20T23:59:00Z", "time_type": "device" } }- Replace
com.example.appwith the actual package name of the app to clear. - Set
start_datetimeandend_datetimein ISO 8601 UTC format. Give the window enough time for the device to come online and execute — at least 30 minutes is recommended. - Replace
your-tenantwith your Esper tenant name andyour-device-uuidwith the UUID copied in step 1. - To clear multiple apps in the same window, submit one API call per package name.
- Replace
-
Set up a cron job for recurring execution. Each API call creates a single scheduled command. To repeat the clear on every shift change or nightly, configure a cron job on your infrastructure to re-submit the request at your desired interval. The cron job should run shortly before the intended
start_datetimeso each new command window aligns with your schedule. For example, to trigger a nightly clear at 23:00 device-local time, schedule the cron job at 22:45 UTC and set the window accordingly.
Verify
Verify: In the Esper Console, go to Devices & Groups → [Device Name] → Command History. After the scheduled window has passed, the CLEAR_APP_DATA command should show a status of Success. When successful, the app's local storage, cache, and session tokens are fully wiped — the next user to open the app will see a clean session with no prior user data.
If this doesn't resolve it
If the command remains in a Queued state after the window has closed, the device was likely offline for the entire window. Check device connectivity in Devices & Groups → [Device Name] → Activity Feed and confirm the device was online during the scheduled interval. Widen end_datetime to give more time for the device to receive and execute the command.
If the command shows Failed, confirm the package name is correct and that the app is installed on the device. Go to Devices & Groups → [Device Name] → Apps to verify the app's installation status.
If the issue persists, contact Esper Support with the following information:
- Device UUID
- The full JSON request body used (redact the bearer token)
- The command ID returned in the API response
- A screenshot of the Command History status from the Esper Console
Still need help?
If you're having trouble scheduling app data clearing with the Esper Commands API, please submit a support ticket and include your WINDOW schedule configuration, the app you're targeting, and any error messages you encountered.
Please sign in to leave a comment.
Comments
0 comments