Code Examples

Take Screenshots with cURL

Ready-to-copy cURL code for capturing website screenshots, generating PDFs, and processing pages at scale. Uses cURL.

Quick Start

Screenshot in cURL — minimal example

The simplest way to capture a screenshot. Just a URL and your API key.

cURLquickstart
curl "https://api.screenshotdev.com/v1/screenshot?url=https://example.com&access_key=YOUR_ACCESS_KEY" \
  --output screenshot.png
Full Example

Production-ready cURL script

Complete working script with options for viewport, format, full page capture, and error handling.

cURLfull example
#!/bin/bash
set -euo pipefail

API_KEY="YOUR_ACCESS_KEY"
BASE="https://api.screenshotdev.com/v1/screenshot"

take_screenshot() {
  local url="$1"
  local format="${2:-webp}"
  local width="${3:-1280}"
  local full_page="${4:-false}"
  local output="${5:-screenshot.$format}"

  local status
  status=$(curl -s -w "%{http_code}" -o "$output" \
    "$BASE" \
    -G \
    -d "url=$url" \
    -d "access_key=$API_KEY" \
    -d "format=$format" \
    -d "width=$width" \
    -d "full_page=$full_page")

  if [ "$status" != "200" ]; then
    echo "Screenshot failed (HTTP $status)" >&2
    cat "$output" >&2
    return 1
  fi
  echo "Saved $output ($(wc -c < "$output" | tr -d ' ') bytes)"
}

take_screenshot "https://example.com" "webp" 1440 true "screenshot.webp"
Advanced

More cURL examples

PDF generation, batch processing, webhooks, CSS/JS injection, and S3 upload.

PDF Generation

cURLpdf
curl "https://api.screenshotdev.com/v1/pdf" \
  -G \
  -d "url=https://example.com" \
  -d "access_key=YOUR_ACCESS_KEY" \
  -d "format=a4" \
  -d "landscape=false" \
  -d "margin=20px" \
  --output page.pdf

Batch Screenshots

cURLbatch
#!/bin/bash
API_KEY="YOUR_ACCESS_KEY"

urls=(
  "https://example.com"
  "https://github.com"
  "https://news.ycombinator.com"
)

for url in "${urls[@]}"; do
  host=$(echo "$url" | sed 's|https\?://||;s|/.*||')
  curl -s "https://api.screenshotdev.com/v1/screenshot" \
    -G \
    -d "url=$url" \
    -d "access_key=$API_KEY" \
    -d "format=webp" \
    --output "$host.webp" &
done
wait
echo "All screenshots saved"

Async with Webhooks

cURLwebhooks
curl -X POST "https://api.screenshotdev.com/v1/screenshot" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "access_key": "YOUR_ACCESS_KEY",
    "webhook_url": "https://your-app.com/api/webhooks/screenshot",
    "format": "webp",
    "full_page": true
  }'

Custom CSS/JS Injection

cURLinject
curl "https://api.screenshotdev.com/v1/screenshot" \
  -G \
  -d "url=https://example.com" \
  -d "access_key=YOUR_ACCESS_KEY" \
  --data-urlencode "inject_css=body { font-family: 'Inter', sans-serif; } .ad { display: none; }" \
  --data-urlencode "inject_js=document.querySelectorAll('[data-cookie-banner]').forEach(el => el.remove())" \
  -d "block_ads=true" \
  --output clean.webp

S3 Upload

cURLs3
# 1. Capture
curl -s "https://api.screenshotdev.com/v1/screenshot" \
  -G \
  -d "url=https://example.com" \
  -d "access_key=YOUR_ACCESS_KEY" \
  -d "format=webp" \
  --output /tmp/screenshot.webp

# 2. Upload to S3
aws s3 cp /tmp/screenshot.webp s3://my-screenshots/captures/example-com.webp \
  --content-type image/webp

Try it live

Test the API in the interactive playground — pre-filled with cURL snippets.

Setup

Installation

Install the HTTP library used in the examples above.

Terminalinstall
# cURL is pre-installed on macOS, Linux, and Windows 10+

Uses cURL. Any HTTP client that supports GET requests will work.

More Examples

Code examples in other languages

Start capturing screenshots
with cURL today.

100 free API calls per month. No credit card. First screenshot in under 30 seconds.

Take Screenshots with cURL — ScreenshotDEV