⌨️ cURL Examples — Quick Reference

Copy-paste ready cURL commands for every SnapAPI endpoint. No SDK required — works from any terminal, CI/CD pipeline, or shell script.

On This Page

Authentication

All requests require your API key in the X-Api-Key header. Get your key from the dashboard.

💡 Tip: Set your API key as an environment variable to avoid repeating it:
export SNAPAPI_KEY="your_api_key_here"

Screenshots

POST /v1/screenshot

Basic Screenshot
curl -X POST "https://api.snapapi.pics/v1/screenshot" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}' \
  --output screenshot.png
Full Page Screenshot
curl -X POST "https://api.snapapi.pics/v1/screenshot" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "format": "png",
    "fullPage": true,
    "width": 1280
  }' \
  --output full-page.png
AVIF Format (Smallest Files)
curl -X POST "https://api.snapapi.pics/v1/screenshot" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "format": "avif",
    "width": 1440,
    "height": 900
  }' \
  --output screenshot.avif
Mobile Device Emulation
curl -X POST "https://api.snapapi.pics/v1/screenshot" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "devicePreset": "iPhone15",
    "format": "png"
  }' \
  --output mobile.png
Block Ads & Cookie Banners
curl -X POST "https://api.snapapi.pics/v1/screenshot" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "format": "png",
    "blockAds": true,
    "blockCookies": true
  }' \
  --output clean.png
Get Hosted URL (JSON Response)
curl -X POST "https://api.snapapi.pics/v1/screenshot" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "format": "png",
    "responseType": "url"
  }'

# Response:
# {"url": "https://cdn.snapapi.pics/screenshots/abc123.png"}

PDF Generation

POST /v1/pdf

Basic PDF
curl -X POST "https://api.snapapi.pics/v1/pdf" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}' \
  --output page.pdf
A4 PDF with Margins
curl -X POST "https://api.snapapi.pics/v1/pdf" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "format": "A4",
    "printBackground": true,
    "margin": {
      "top": "20mm",
      "bottom": "20mm",
      "left": "15mm",
      "right": "15mm"
    }
  }' \
  --output document.pdf
PDF from HTML
curl -X POST "https://api.snapapi.pics/v1/pdf" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Invoice #1234</h1><p>Total: $99.00</p>",
    "format": "A4",
    "printBackground": true
  }' \
  --output invoice.pdf

Content Extraction

POST /v1/extract

Extract Markdown
curl -X POST "https://api.snapapi.pics/v1/extract" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/blog-post",
    "format": "markdown"
  }'

# Response:
# {"markdown": "# Blog Post Title\n\nArticle content..."}
Extract Structured Data
curl -X POST "https://api.snapapi.pics/v1/extract" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/product",
    "format": "structured",
    "schema": {
      "title": "string",
      "price": "number",
      "description": "string"
    }
  }'

Advanced Options

Custom Headers & Cookies

curl -X POST "https://api.snapapi.pics/v1/screenshot" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/dashboard",
    "format": "png",
    "headers": {
      "Authorization": "Bearer your-token",
      "Cookie": "session=abc123"
    }
  }' \
  --output dashboard.png

Custom CSS & JavaScript Injection

curl -X POST "https://api.snapapi.pics/v1/screenshot" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "format": "png",
    "css": "body { background: #1a1a2e; color: white; }",
    "js": "document.querySelector(\".popup\")?.remove();"
  }' \
  --output styled.png

Delay & Wait for Element

curl -X POST "https://api.snapapi.pics/v1/screenshot" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "format": "png",
    "delay": 3000,
    "waitForSelector": "#main-content"
  }' \
  --output delayed.png

Error Handling

Check HTTP status codes to handle errors:

# Check response status
response=$(curl -s -w "\n%{http_code}" -X POST "https://api.snapapi.pics/v1/screenshot" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}' \
  --output screenshot.png)

http_code=$(echo "$response" | tail -1)

case $http_code in
  200) echo "Success! Screenshot saved." ;;
  400) echo "Bad request - check your parameters" ;;
  401) echo "Invalid API key" ;;
  429) echo "Rate limit exceeded - slow down" ;;
  500) echo "Server error - try again later" ;;
  *)   echo "Unexpected status: $http_code" ;;
esac
⚠️ Rate Limits: Free tier: 200 requests/month. Check the X-RateLimit-Remaining response header. Upgrade for higher limits.

Shell Scripts

Batch Screenshots

#!/bin/bash
# batch-screenshots.sh — Capture screenshots for a list of URLs

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

for i in "${!URLS[@]}"; do
  echo "Capturing ${URLS[$i]}..."
  curl -s -X POST "https://api.snapapi.pics/v1/screenshot" \
    -H "X-Api-Key: $SNAPAPI_KEY" \
    -H "Content-Type: application/json" \
    -d "{\"url\": \"${URLS[$i]}\", \"format\": \"png\"}" \
    --output "screenshot_$i.png"
  echo "  → screenshot_$i.png"
done

echo "Done! Captured ${#URLS[@]} screenshots."

Screenshot with Timestamp

#!/bin/bash
# timestamped-screenshot.sh — Capture with date-based filename

URL="${1:-https://example.com}"
FILENAME="screenshot_$(date +%Y%m%d_%H%M%S).png"

curl -s -X POST "https://api.snapapi.pics/v1/screenshot" \
  -H "X-Api-Key: $SNAPAPI_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"url\": \"$URL\", \"format\": \"png\"}" \
  --output "$FILENAME"

echo "Saved: $FILENAME"

Monitor Website Changes

#!/bin/bash
# monitor.sh — Take periodic screenshots for visual monitoring

URL="https://example.com"
INTERVAL=3600  # seconds (1 hour)

while true; do
  FILENAME="monitor_$(date +%Y%m%d_%H%M%S).png"
  curl -s -X POST "https://api.snapapi.pics/v1/screenshot" \
    -H "X-Api-Key: $SNAPAPI_KEY" \
    -H "Content-Type: application/json" \
    -d "{\"url\": \"$URL\", \"format\": \"png\", \"fullPage\": true}" \
    --output "$FILENAME"
  echo "[$(date)] Captured → $FILENAME"
  sleep $INTERVAL
done

Next Steps