Lab Test API
The lab test API lets you create monitored pages, trigger tests, fetch results, and export monitoring data.
Creating a page
Pages live inside a project. Call createPage on the project (or debugbear.pages.create(projectId, …)) to add one. See the Projects API for managing projects.
const { DebugBear } = require("debugbear");
const debugbear = new DebugBear(process.env.DEBUGBEAR_API_KEY);
const project = await debugbear.projects.get(projectId);
const page = await project.createPage({
name: "Example",
url: "http://example.com/",
region: "germany",
testScheduleName: "Every 12 hours",
deviceName: "Desktop",
advancedSettings: ["Staging Basic Auth"],
tags: ["Tag 1"],
});
console.log(page);
The created page:
{
"id": "11111",
"name": "Example",
"url": "http://example.com/",
"region": "germany",
"testSchedules": [
{ "id": "22222", "name": "Every 12 hours" }
],
"device": {
"id": "33333",
"name": "Desktop",
"rtt": 40,
"bandwidthKbps": 8192,
"formFactor": "desktop",
"cpuThrottling": 1
},
"advancedSettings": [
{ "id": "18", "name": "Staging Basic Auth", "type": "basicAuth" }
],
"tags": ["Tag 1"]
}
Using cURL
curl https://www.debugbear.com/api/v1/projects/123456/pages \
-X POST \
-H "x-api-key: API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Example Homepage", "url": "https://example.com", "region": "uk", "tags": ["homepage"]}'
Updating a page
await debugbear.pages.update(PAGE_ID, {
tags: ["staging"],
advancedSettings: ["Staging Auth"],
});
Deleting a page
await project.deletePage(page.id);
Using cURL
curl https://www.debugbear.com/api/v1/pages/123456 \
-X DELETE \
-H "x-api-key: API_KEY"
Valid test server regions
See server locations for the supported region values.
Running a website test
You can either run a single test or trigger tests in bulk.
Create a script.js file like this:
const { DebugBear } = require("debugbear");
// TypeScript: import { DebugBear } from "debugbear"
const debugbear = new DebugBear(process.env.DEBUGBEAR_API_KEY);
const pageId = 185;
debugbear.pages.analyze(pageId).then((analysis) => {
analysis.waitForResult().then(() => {
console.log("Test complete, view results here: " + analysis.url);
});
});
Then run DEBUGBEAR_API_KEY=... node script.js.
Additional options
The Node module supports similar arguments to the CLI.
Building a particular commit
debugbear.pages.analyze(pageId, {
commitHash: "e2ba122",
buildTitle: "Add support for tags",
// infer additional details from the environment, for
// example the name of the current branch
inferBuildInfo: true,
});
Customizing the url and HTTP headers
debugbear.pages.analyze(pageId, {
url: "http://staging.com",
customHeaders: {
"X-Feature-Flags": "tags",
},
});
Passing in custom cookies
debugbear.pages.analyze(pageId, {
cookies: [
{
name: "testcookie",
value: "testvalue",
domain: "www.example.com",
path: "/",
},
],
});