### BrowserStack API Authentication Example Source: https://github.com/browserstack/api/blob/v5/README.md Demonstrates how to authenticate with the BrowserStack API using username and access key via cURL. Authentication is required for all API requests. ```bash curl -u "username:access_key" https://api.browserstack.com/5 ``` -------------------------------- ### BrowserStack API - Getting Available Browsers (Nested Structure) Source: https://github.com/browserstack/api/blob/v5/README.md Fetches a list of all available browsers supported by BrowserStack, organized by operating system and version. Requires authentication. ```http GET /browsers ``` ```bash curl -u "username:access_key" https://api.browserstack.com/5/browsers ``` ```javascript { 'Windows': { '10': [ { "browser": "chrome", "browser_version": "83.0" }, { "browser": "chrome", "browser_version": "84.0" }, { "browser": "chrome", "browser_version": "85.0 beta" }, { "browser": "ie", "browser_version": "11.0" }, { "browser": "edge", "browser_version": "insider preview" }... ], }, 'OS X': { 'Catalina': [ { "browser": "chrome", "browser_version": "85.0 beta" }, { "browser": "edge", "browser_version": "85.0 beta" }, { "browser": "safari", "browser_version": "13.1" }, { "browser": "firefox", "browser_version": "79.0" }, { "browser": "firefox", "browser_version": "80.0 beta" }... ], }... }, } ``` -------------------------------- ### Example Worker Status Response Source: https://github.com/browserstack/api/blob/v5/README.md Provides an example of the JSON response when checking the status of a single worker. ```javascript { status: 'running', browser: 'ie', browser_version: '6.0', os: 'Windows', os_version: 'XP', sessionId: "", browser_url: "" } ``` -------------------------------- ### Example List of Workers Response Source: https://github.com/browserstack/api/blob/v5/README.md Demonstrates the JSON response format for retrieving a list of all active workers. ```javascript [ { status: 'running', browser: 'ie', version: '6.0', os: 'Windows', os_version: 'XP', sessionId: "", browser_url: "" }, { status: 'queue', device: 'Samsung Galaxy Tab 8.9', os: 'android', os_version: '2.2', sessionId: "", browser_url: "" } ... ] ``` -------------------------------- ### Example API Status Response Source: https://github.com/browserstack/api/blob/v5/README.md Shows the JSON response format for the API status endpoint, detailing time usage and session limits. ```javascript { "used_time": 4235.4, "total_available_time": 6000, "running_sessions": 1, "sessions_limit": 1 } ``` -------------------------------- ### Example Out of API Time Response Source: https://github.com/browserstack/api/blob/v5/README.md Illustrates the response when a user has exhausted their allocated API time. ```javascript { "message": "You have run out of API time" } ``` -------------------------------- ### BrowserStack API - Getting Available Browsers (Flat Structure) Source: https://github.com/browserstack/api/blob/v5/README.md Fetches a flat list of all available browsers supported by BrowserStack, including OS, OS version, browser, and browser version. Requires authentication. ```http GET /browsers?flat=true ``` ```bash curl -u "username:access_key" https://api.browserstack.com/5/browsers?flat=true ``` ```javascript [ { "os": "Windows", "os_version": "10", "browser": "chrome", "device": null, "browser_version": "84.0", "real_mobile": null }, { "os": "Windows", "os_version": "10", "browser": "edge", "device": null, "browser_version": "85.0 beta", "real_mobile": null }, { "os": "OS X", "os_version": "Catalina", "browser": "firefox", "device": null, "browser_version": "79.0", "real_mobile": null }, { "os": "OS X", "os_version": "Catalina", "browser": "firefox", "device": null, "browser_version": "80.0 beta", "real_mobile": null }.... ] ``` -------------------------------- ### Example BrowserStack API Response Source: https://github.com/browserstack/api/blob/v5/README.md Illustrates the structure of a typical response when retrieving information about browser workers, including details like ID, status, OS, browser, and session information. ```javascript [ { "id": "", "status": "running", "os": "OS X", "os_version": "Mojave", "browser": "chrome", "browser_version": "75.0", "real_mobile": null, "device": null, "browser_url": "", "sessionId": "" }, { "id": "", "status": "queue", "os": "android", "os_version": "2.2", "device": "Samsung Galaxy S", "browser": "Android Browser", "browser_version": null, "real_mobile": false, "browser_url": "", "sessionId": "" } ... ] ``` -------------------------------- ### BrowserStack API Error Response Example Source: https://github.com/browserstack/api/blob/v5/README.md Illustrates a typical error response from the BrowserStack API when a required parameter is missing. Error codes like 'required' and 'invalid' are used. ```http HTTP/1.1 422 Unprocessable Entity Content-Length: 136 { "message": "Validation Failed", "errors": [ { "field": "type", "code": "required" } ] } ``` -------------------------------- ### Get Details of all Browser Workers Source: https://github.com/browserstack/api/blob/v5/README.md Retrieves comprehensive information for all created browser workers, including their ID, current URL, session ID, and status (queue or running). ```http GET /workers ``` ```bash curl -u "username:access_key" -X GET https://api.browserstack.com/5/workers ``` -------------------------------- ### BrowserStack API Schema and Version Check Source: https://github.com/browserstack/api/blob/v5/README.md Shows how to check the API version and retrieve basic information. All requests are made to `https://api.browserstack.com/VERSION/` and responses are in JSON format. ```bash curl -i -u "username:access_key" https://api.browserstack.com/5 ``` -------------------------------- ### BrowserStack API - Schema and Date Format Source: https://github.com/browserstack/api/blob/v5/README.md Details the API schema, base URL, and date format. All responses are in JSON, and dates follow ISO-8601 standard. ```APIDOC Schema: Base URL: `https://api.browserstack.com/VERSION/` Response Format: JSON Date Format: ISO-8601 (e.g., `YYYY-MM-DDTHH:mm:ss.sssZ`) ``` -------------------------------- ### BrowserStack API - HTTP Verbs Source: https://github.com/browserstack/api/blob/v5/README.md Defines the standard HTTP verbs used by the BrowserStack API for concise and predictable interactions with resources. ```APIDOC HTTP Verbs: - HEAD: Retrieves resource status without content. - GET: Retrieves resources. - POST: Creates new resources. - PUT: Updates resources. - DELETE: Deletes resources. ``` -------------------------------- ### BrowserStack API - Authentication Source: https://github.com/browserstack/api/blob/v5/README.md Explains the authentication mechanism for the BrowserStack API, requiring username and access key for all requests. ```APIDOC Authentication: All API methods require authentication using your username and BrowserStack access key. Format: `curl -u "username:access_key" ` Error on unauthorized access: `401 Unauthorized`. ``` -------------------------------- ### Create Browser Worker Source: https://github.com/browserstack/api/blob/v5/README.md Creates a new browser worker instance. Requires authentication and specifies browser, OS, and URL details. The response includes a unique worker ID. ```http POST /worker ``` ```bash curl -u "username:access_key" -X POST -d '{"os":"OS X","os_version":"Mojave","url":"https://browserstack.com","browser":"chrome","browser_version":"75.0"}' https://api.browserstack.com/5/worker -H 'content-type: application/json' ``` ```http HTTP/1.1 200 Success Content-Type: application/json X-API-Version: 5 { "id": "123456789" } ``` -------------------------------- ### BrowserStack API - Error Handling Source: https://github.com/browserstack/api/blob/v5/README.md Outlines the error handling strategy for the BrowserStack API, including common error codes and response structure. ```APIDOC Error Handling: API requests are validated. Errors include: - `422 Unprocessable Entity`: For validation failures. - Error Codes: `required`, `invalid`. Example Response: ```http HTTP/1.1 422 Unprocessable Entity Content-Length: 136 { "message": "Validation Failed", "errors": [ { "field": "type", "code": "required" } ] } ``` ``` -------------------------------- ### BrowserStack API Status Check Source: https://github.com/browserstack/api/blob/v5/README.md Details the API endpoint for checking the overall status of the BrowserStack API, including usage metrics. ```APIDOC Getting API Status: GET /status - Description: Retrieves the current status of the BrowserStack API, including API time used and parallel workers. - Authentication: Requires authentication. - Response: - JSON object with used_time (in seconds), total_available_time, running_sessions, and sessions_limit. - Example: curl -u "username:access_key" https://api.browserstack.com/5/status - Response Example: { "used_time": 4235.4, "total_available_time": 6000, "running_sessions": 1, "sessions_limit": 1 } - Out of Time Response: - If API time is exhausted, returns a JSON object with a 'message' indicating the issue. - Example: { "message": "You have run out of API time" } - Rate Limiting: Up to 1600 API requests are allowed every 5 minutes. ``` -------------------------------- ### Take Screenshot of Browser Worker Source: https://github.com/browserstack/api/blob/v5/README.md Captures a screenshot of the current state of a browser worker. Supports JSON, XML, or PNG formats, which can be specified in the URL or Accept header. ```http GET /worker//screenshot(.format) ``` ```bash curl -u "username:access_key" https://api.browserstack.com/5/worker/123456789/screenshot.json ``` -------------------------------- ### BrowserStack API Worker Management Source: https://github.com/browserstack/api/blob/v5/README.md Provides API endpoints for managing browser workers, including terminating a specific worker and retrieving the status of workers. ```APIDOC Terminating a Browser Worker: DELETE /worker/ - Description: Terminates a specific browser worker. Useful for stopping indefinite sessions or saving credits. - Parameters: - id: The unique identifier of the worker to terminate. - Authentication: Requires authentication. Unauthorized requests receive a `401 Unauthorized`. - Authorization: If the user is not the owner or the ID does not exist, a `403 Forbidden` response is given. - Rate Limiting: Requests made within 60 seconds of worker start result in a `422 Unprocessable Entity` and termination after 60 seconds of runtime. - Example: curl -u "username:access_key" -X DELETE https://api.browserstack.com/5/worker/123456789 Getting Worker Status: GET /worker/ - Description: Retrieves the status of a specific worker (queue, running, or terminated). - Parameters: - id: The unique identifier of the worker. - Authentication: Requires authentication. Unauthorized requests receive a `401 Unauthorized`. - Authorization: If the user is not the owner, a `403 Forbidden` response is given. - Response: - If terminated: Empty response. - Otherwise: JSON object with status, browser, browser_version, os, os_version, sessionId, and browser_url. - Example: curl -u "username:access_key" https://api.browserstack.com/5/worker/123456789 Getting All Worker Statuses: GET /workers - Description: Retrieves a list of all currently running or queued workers. - Authentication: Requires authentication. Unauthorized requests receive a `401 Unauthorized`. - Authorization: If the user is not the owner, a `403 Forbidden` response is given. - Response: JSON array of worker objects, each containing status, browser, version, os, os_version, sessionId, and browser_url. - Example: curl -u "username:access_key" https://api.browserstack.com/5/workers ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.