Integration Guides
This section provides step-by-step guides on how to integrate Screenshotly into your existing projects and workflows.
General Integration Principles
Before diving into specific guides, here are some general principles:
- API Key: Ensure you have your Screenshotly API key, which can be found in your account dashboard.
- Authentication: All API requests must be authenticated using your API key in the Authorization header. See the API Reference for details.
- Error Handling: Implement robust error handling in your integration to manage potential API errors. Refer to the Error Handling section in the API reference.
Platform & Language Guides
Choose a guide below based on your technology stack:
1. Node.js / JavaScript
Using the screenshotly-js Client Library
We provide an official JavaScript client library for easy integration with Screenshotly.
Installation
npm install screenshotly-js
Or with yarn:
yarn add screenshotly-js
Basic Example
const { Screenshotly } = require('screenshotly-js');
// Initialize the client with your API key
const client = new Screenshotly('your-api-key-here');
// Capture a screenshot of a URL
async function captureScreenshot() {
const screenshot = await client.capture({
url: 'https://example.com',
width: 1280,
height: 800,
fullPage: true,
delay: 500
});
if (screenshot.success) {
console.log('Screenshot URL:', screenshot.data.imageUrl);
console.log('Remaining credits:', screenshot.remainingCredits);
} else {
console.error('Error:', screenshot.error);
}
}
captureScreenshot();
Batch Screenshots
const { Screenshotly } = require('screenshotly-js');
const client = new Screenshotly('your-api-key-here');
async function captureBatchScreenshots() {
const result = await client.captureBatch({
urls: [
'https://example.com',
'https://google.com',
'https://github.com'
],
options: {
format: 'png',
width: 1280,
height: 800,
fullPage: true,
delay: 500
}
});
if (result.success) {
console.log('Screenshots:', result.data);
console.log('Remaining credits:', result.remainingCredits);
} else {
console.error('Error:', result.error);
}
}
captureBatchScreenshots();
Advanced Options
const { Screenshotly } = require('screenshotly-js');
// You can also pass configuration options
const client = new Screenshotly({
apiKey: 'your-api-key-here',
baseUrl: 'https://api.screenshotly.dev',
timeout: 90000 // 90 seconds timeout for large pages
});
async function captureWithAdvancedOptions() {
const screenshot = await client.capture({
url: 'https://example.com',
format: 'png',
width: 1920,
height: 1080,
fullPage: true,
deviceScaleFactor: 2, // Retina-quality screenshot
isMobile: true,
hasTouch: true,
waitForSelector: '.content-loaded',
delay: 1000, // Wait 1 second before capturing
timeout: 45000 // 45 seconds timeout
});
console.log('Screenshot URL:', screenshot.data.imageUrl);
}
API Reference
Screenshotly Class
Constructor
// Simple format
new Screenshotly(apiKey)
// Advanced format
new Screenshotly(config)
- (string): Your Screenshotly API key
apiKey
- (required): Your Screenshotly API key
config.apiKey
- (optional): Custom API base URL (default: 'https://api.screenshotly.dev')
config.baseUrl
- (optional): Request timeout in milliseconds (default: 60000)
config.timeout
Methods
capture(options): Promise