How to Archive Logs on a Device Using API

Modified on Sun, Jun 14 at 2:27 PM

Overview

This API allows users to execute an ADB shell command on a device to archive log files or perform other shell-based operations. It is commonly used to compress and package device logs into an archive that can later be downloaded and analyzed for troubleshooting purposes.


Endpoint

URL: https://{your_base_url}.testgrid.io/api/execute-shell-adb-native/{device_id}

Method: POST


Request Parameters

ParameterTypeRequiredDescription
device_idIntegerYesUnique identifier of the target device
ParameterTypeRequiredDescription
user_tokenStringYesUser authentication token
commandStringYesShell command to execute on the device

Example Request

curl --location 'https://{your_base_url}.testgrid.io/api/execute-shell-adb-native/1'
--form 'user_token="YOUR_USER_TOKEN"'
--form 'command="shell tar -czvf sdcard/Android/data/com.android.numeracle.screencapture/files/CallCapture/CallCaptureLogs/mylogs_archive.tar.gz sdcard/Android/data/com.android.numeracle.screencapture/files/CallCapture/CallCaptureLogs"'


Example Response


{
"success": true,
"message": "Command executed successfully.",
"output": "sdcard/Android/data/com.android.numeracle.screencapture/files/CallCapture/CallCaptureLogs/\nsdcard/Android/data/com.android.numeracle.screencapture/files/CallCapture/CallCaptureLogs/Callcapture_app_logs.txt\ntar: 'mylogs_archive.tar.gz' file is the archive; not dumped\ntar: had errors",
"file_url": ""
}


Response Parameters

ParameterTypeDescription
successBooleanIndicates whether the command executed successfully
messageStringResult of the command execution
outputStringStandard output generated by the shell command
file_urlStringURL of the generated archive file, if available

Notes

  • The API executes shell commands directly on the specified device.

  • Ensure that the target device is online and accessible before sending the request.

  • The command output may contain warnings or errors generated by the underlying shell command.

  • The file_url field remains empty if archive creation fails.

  • Verify that the provided device_id corresponds to the intended device.

  • A valid user_token is required for authentication.


Outcome

The API executes the specified shell command on the target device and returns the command output. When archive creation is successful, the resulting archive can be used for log collection, troubleshooting, debugging, and analysis purposes.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article