API Reference
Welcome to the Screenshotly API reference. This document provides all the information you need to interact with the Screenshotly API programmatically.
Introduction
The Screenshotly API is a powerful and flexible tool for capturing high-quality screenshots of web pages. Integrate it into your application to automate the process of generating visual content.
Client Libraries
We provide official client libraries to make integration with Screenshotly even easier:
- JavaScript/Node.js: - Our official JavaScript client for Node.js and browser environments
screenshotly-js
- Python: Coming soon
- PHP: Coming soon
Authentication
All API requests must be authenticated. Screenshotly uses API Keys to allow access to the API.
- API Key: You can obtain your API key from your account dashboard.
- Header: Include your API key in the screenshotly-api-key header of your requests.
screenshotly-api-key: YOUR_API_KEY
Rate Limiting
Our API has a rate limit of X requests per minute per API key. If you exceed this limit, you will receive a "429 Too Many Requests" HTTP status code.
Error Handling
The Screenshotly API uses standard HTTP status codes to indicate the success or failure of an API request.
- 2xx status codes indicate success.
- 4xx status codes indicate an error that failed given the information provided (e.g., a required parameter was omitted, a charge failed, etc.).
- 5xx status codes indicate an error with Screenshotly's servers (these are rare).
Common error codes include:
Status Code | Meaning | Description |
---|---|---|
400 | Bad Request | Your request is malformed. |
401 | Unauthorized | Your API key is wrong or missing. |
403 | Forbidden | You do not have permission to access this resource. |
404 | Not Found | The requested resource could not be found. |
429 | Too Many Requests | You're hitting the API too often. Please slow down. |
500 | Internal Server Error | We had a problem with our server. Try again later. |
Endpoints
1. Capture Screenshot
This endpoint allows you to request a screenshot of a given URL.
- Method: POST
- URL: "/api/v1/screenshots"
Headers:
"screenshotly-api-key: YOUR_API_KEY"
"Content-Type: application/json"
Body Parameters (JSON):
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
url | String | Yes | The URL of the webpage to capture. | "https://example.com" |
format | String | No | The desired format of the screenshot. Options: png, jpeg, webp. Defaults to png. | "jpeg" |
width | Integer | No | The width of the browser viewport in pixels. Defaults to 1920. | 1280 |
height | Integer | No | The height of the browser viewport in pixels. Defaults to 1080. | 720 |
fullPage | Boolean | No | Whether to capture the full scrollable page. Defaults to false. | true |
- Success Response (202 Accepted):
Indicates that the screenshot request has been accepted and is being processed. If
webhookUrl is not provided, the response will contain the direct URL to the screenshot once ready. If webhookUrl is provided, the response will be minimal, and the result will be sent to the webhook.
{ "status": "processing", "id": "some-unique-screenshot-id", "message": "Screenshot request accepted and is being processed.", // "screenshotUrl": "https://api.screenshotly.dev/api/v1/screenshots/some-unique-id.png" // If no webhook }
- Error Response: See Error Handling.
2. Get Screenshot Status / Details
Retrieve the status or details of a previously submitted screenshot job.
- Method: GET
- URL: "/api/v1/screenshots/{screenshotId}"
- Headers:
- "screenshotly-api-key: YOUR_API_KEY"
- Path Parameters:
Parameter Type Description screenshotId String The ID of the screenshot job. - Success Response (200 OK):
{ "id": "some-unique-job-id", "status": "completed", // or "processing", "failed" "url": "https://example.com", "requestedAt": "2025-05-14T10:00:00Z", "completedAt": "2025-05-14T10:00:05Z", // if completed "screenshotUrl": "https://api.screenshotly.dev/api/v1/screenshots/some-unique-id.png", // if completed "format": "png", "error": null // or error message if status is "failed" }
- Error Response: See Error Handling.
JavaScript Client
Our official JavaScript client library,
screenshotly-js
Installation
npm install screenshotly-js
# or
yarn add screenshotly-js
Usage
const { Screenshotly } = require('screenshotly-js');
// Initialize with your API key
const client = new Screenshotly('your-api-key-here');
// Or with advanced options
const clientWithOptions = new Screenshotly({
apiKey: 'your-api-key-here',
baseUrl: 'https://api.screenshotly.dev', // optional custom API URL
timeout: 60000 // optional timeout in milliseconds
});
API Methods
capture(options)
Captures a screenshot of a specified URL.
const screenshot = await client.capture({
url: 'https://example.com',
width: 1280,
height: 800,
fullPage: true,
format: 'png',
delay: 500
});
if (screenshot.success) {
console.log('Screenshot URL:', screenshot.data.imageUrl);
console.log('Remaining credits:', screenshot.remainingCredits);
} else {
console.error('Error:', screenshot.error);
}
Parameters:
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
url | String | Yes | - | URL to capture |
name | String | No | - | Optional name for the screenshot |
width | Number | No | 1920 | Width of the viewport in pixels |
height | Number | No | 1080 | Height of the viewport in pixels |
fullPage | Boolean | No | false | Whether to capture the full page or just the viewport |
format | String | No | 'png' | Output format ('png', 'jpeg', 'webp') |
deviceScaleFactor | Number | No | 1 | Device scale factor (1 = normal, 2 = retina) |
isMobile | Boolean | No | false | Whether to emulate a mobile device |
hasTouch | Boolean | No | false | Whether the device has touch capabilities |
isLandscape | Boolean | No | false | Whether to use landscape orientation |
waitForSelector | String | No | - | Optional selector to wait for before taking the screenshot |
delay | Number | No | 0 | Delay in milliseconds before capturing the screenshot |
timeout | Number | No | 30000 | Timeout in milliseconds |
captureBatch(request)
Captures multiple screenshots in batch.
const result = await client.captureBatch({
urls: [
'https://example.com',
'https://google.com',
'https://github.com'
],
options: {
format: 'png',
width: 1280,
height: 800,
fullPage: true
}
});
if (result.success) {
console.log('Screenshots:', result.data);
console.log('Remaining credits:', result.remainingCredits);
} else {
console.error('Error:', result.error);
}
Parameters:
Parameter | Type | Required | Description |
---|---|---|---|
urls | Array | Yes | Array of URLs to take screenshots of |
options | Object | No | Screenshot options (applied to all URLs) |
getScreenshots(page, limit)
Gets a list of your screenshots.
const screenshots = await client.getScreenshots(1, 10);
console.log('Screenshots:', screenshots.data);
Parameters:
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
page | Number | No | 1 | Page number |
limit | Number | No | 10 | Number of items per page |
getScreenshot(id)
Gets a specific screenshot by ID.
const screenshot = await client.getScreenshot('screenshot-id');
console.log('Screenshot:', screenshot.data);
deleteScreenshot(id)
Deletes a screenshot by ID.
const result = await client.deleteScreenshot('screenshot-id');
console.log('Deleted:', result.success);
For more detailed examples and advanced usage, see our Integration Guides.
Code Examples
Here are some examples of how to use the Screenshotly API in different programming languages.
JavaScript (Node.js - axios)
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY';
const SCREENSHOTLY_API_ENDPOINT = 'https://api.screenshotly.dev/api/v1/screenshots';
async function captureScreenshot(urlToCapture) {
try {
const response = await axios.post(
SCREENSHOTLY_API_ENDPOINT,
{
url: urlToCapture,
format: 'jpeg',
fullPage: true,
},
{
headers: {
'screenshotly-api-key': API_KEY,
'Content-Type': 'application/json',
},
}
);
console.log('API Response:', response.data);
// If not using webhooks, response.data.screenshotUrl will contain the image URL
} catch (error) {
console.error('Error capturing screenshot:', error.response ? error.response.data : error.message);
}
}
captureScreenshot('https://example.com');
Python (using requests library)
import requests
import json
API_KEY = "YOUR_API_KEY"
SCREENSHOTLY_API_ENDPOINT = "https://api.screenshotly.dev/api/v1/screenshots"
def capture_screenshot(url_to_capture):
headers = {
"screenshotly-api-key": API_KEY,
"Content-Type": "application/json",
}
payload = {
"url": url_to_capture,
"format": "png",
"width": 1920,
"height": 1080,
}
try:
response = requests.post(SCREENSHOTLY_API_ENDPOINT, headers=headers, data=json.dumps(payload))
response.raise_for_status() # Raises an HTTPError for bad responses (4XX or 5XX)
print("API Response:", response.json())
# If not using webhooks, response.json().get("screenshotUrl") will contain the image URL
except requests.exceptions.HTTPError as errh:
print(f"Http Error: {errh} - {errh.response.text}")
except requests.exceptions.ConnectionError as errc:
print(f"Error Connecting: {errc}")
except requests.exceptions.Timeout as errt:
print(f"Timeout Error: {errt}")
except requests.exceptions.RequestException as err:
print(f"Oops: Something Else: {err}")
capture_screenshot("https://example.com")
Changelog
Stay updated with the latest changes to our API.
- v1.0.0 (2025-05-14)
- Initial API release.
- Endpoints: "/screenshots", "/screenshots/{screenshotId}".