SDK Examples
Code examples for common languages and tools.
TypeScript / Node.js
const API_URL = "https://api.thepixelhouse.co.uk";
const API_KEY = process.env.PIXELHOUSE_API_KEY;
// Capture a screenshot
const response = await fetch(`${API_URL}/v1/screenshots`, {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://example.com",
viewport: "desktop",
projectId: "prj_your_project_id",
}),
});
const { data } = await response.json();
console.log("Screenshot:", data.id, data.imageUrl);
// Run a visual regression test
const testResponse = await fetch(`${API_URL}/v1/tests/run`, {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://example.com",
baselineId: "bl_your_baseline_id",
viewport: "desktop",
threshold: 1.0,
}),
});
const { data: result } = await testResponse.json();
console.log(`Status: ${result.status}, Diff: ${result.diffPercentage}%`);Python
import requests
import os
API_URL = "https://api.thepixelhouse.co.uk"
API_KEY = os.environ["PIXELHOUSE_API_KEY"]
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
}
# Capture a screenshot
response = requests.post(f"{API_URL}/v1/screenshots", headers=headers, json={
"url": "https://example.com",
"viewport": "desktop",
"projectId": "prj_your_project_id",
})
data = response.json()["data"]
print(f"Screenshot: {data['id']}")
# Run a visual regression test
response = requests.post(f"{API_URL}/v1/tests/run", headers=headers, json={
"url": "https://example.com",
"baselineId": "bl_your_baseline_id",
"viewport": "desktop",
"threshold": 1.0,
})
result = response.json()["data"]
print(f"Status: {result['status']}, Diff: {result['diffPercentage']}%")cURL
# Capture a screenshot
curl -X POST https://api.thepixelhouse.co.uk/v1/screenshots \
-H "Authorization: Bearer $PIXELHOUSE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com","viewport":"desktop","projectId":"prj_xxx"}'
# Run a visual regression test
curl -X POST https://api.thepixelhouse.co.uk/v1/tests/run \
-H "Authorization: Bearer $PIXELHOUSE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com","baselineId":"bl_xxx","threshold":1.0}'
# List projects
curl https://api.thepixelhouse.co.uk/v1/projects \
-H "Authorization: Bearer $PIXELHOUSE_API_KEY"