Installation
Install the Gbox SDK using your preferred package manager:
Basic Usage
1. Initialize the SDK
First, import and initialize the SDK with your API key for authentication:
import GboxSDK from "gbox-sdk";
const gboxSDK = new GboxSDK({
apiKey: process.env["GBOX_API_KEY"], // Recommended: use environment variables
});
2. Create Virtual Devices
Use the SDK to create different types of virtual devices:
async function createAndroidBox() {
try {
const box = await gboxSDK.create({
type: "android",
// Optional: add other configuration parameters
});
console.log("Android device created successfully:", box.id);
return box;
} catch (error) {
console.error("Failed to create Android device:", error);
}
}
createAndroidBox();
3. Complete Example
Here’s a complete example showing how to create a device and perform basic operations:
import GboxSDK from "gbox-sdk";
const gboxSDK = new GboxSDK({
apiKey: process.env["GBOX_API_KEY"],
});
async function main() {
try {
// Create an Android device
const box = await gboxSDK.create({ type: "android" });
console.log(`Device created successfully, ID: ${box.id}`);
// Start the device
await gboxSDK.startBox({ id: box.id });
console.log("Device started successfully");
// Wait for device to be ready...
// Stop the device
await gboxSDK.stopBox({ id: box.id });
console.log("Device stopped");
} catch (error) {
console.error("Operation failed:", error);
}
}
main();
Next Steps