Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To take a screenshot from Bash, send an authenticated HTTP request to a hosted screenshot API and save its binary response with curl --output. For a simple capture, GET is usually the shortest path; use POST when the provider offers structured rendering options. Keep API keys out of scripts and URLs, and check the HTTP status before treating the saved file as an image.

Quick start: save a webpage screenshot with Bash

Screenshot API providers differ in endpoint, authentication, parameter names, and response format, so there is no universal request that works unchanged for every service. The following GET example follows Screenshot API.net’s documented raw-image-byte pattern. Store the key in an environment variable, URL-encode the target, and write the response directly to a file:

export SCREENSHOT_API_KEY="YOUR_API_KEY"
curl --fail-with-body -G "https://screenshot-api.net/v1/screenshot" 
  -H "Authorization: Bearer $SCREENSHOT_API_KEY" 
  --data-urlencode "url=https://example.com" 
  -o shot.png

Replace YOUR_API_KEY with a key issued by that provider. The -G option tells curl to send the supplied data as GET query parameters; --data-urlencode safely encodes the target URL, including its own query string. -o saves the response body as bytes rather than printing it in the terminal. Screenshot API.net documents this endpoint as returning raw image bytes: Screenshot API.net documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a file extension that matches the format requested or returned by the API. If the provider lets you choose a format, request PNG when you need lossless detail, JPEG for a smaller photographic image, or WebP where your downstream tools support it. The exact format parameter and defaults are provider-specific.

How to choose GET or POST

Use the method supported by the API’s current contract. GET is convenient for a URL and a few scalar settings. POST is often easier to read for structured or advanced options, such as nested viewport settings, custom CSS or JavaScript, selector hiding, geolocation, PDF settings, or batch capture—when the service supports those options. Do not assume that option names or capabilities transfer between providers.

Request style Good fit What to verify
GET with query parameters A single target URL and a small number of simple settings. Endpoint, authentication format, supported query names, output format, and whether the response is raw bytes or JSON.
POST with JSON Structured settings or a payload that is cumbersome as query parameters. JSON field names, content type, supported controls, batch behavior, and whether the response contains bytes or a JSON result or URL.

A URL response and an image response require different handling: saving JSON that contains a link to shot.png does not create an image file. Check the provider’s documentation to learn whether a successful capture is returned directly as bytes or represented by JSON or a URL. For examples of the different response contracts, see Screenshot API’s REST documentation, ScreenshotEngine’s quickstart, and Screenshot API.net’s documentation.

POST examples for screenshot captures

ScreenshotEngine: direct image response

ScreenshotEngine documents a POST request whose successful response is the image file itself and whose errors return JSON. This example requests a full-height PNG:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
export SCREENSHOTENGINE_API_KEY="YOUR_API_KEY"
curl --fail-with-body --request POST 'https://api.screenshotengine.com/v1/screenshot' 
  --header "Authorization: Bearer $SCREENSHOTENGINE_API_KEY" 
  --header 'Content-Type: application/json' 
  --data '{"url":"https://example.com","format":"png","height":"full"}' 
  --output screenshot.png

With --fail-with-body, curl returns a nonzero exit status for an HTTP error while retaining the response body, which can help diagnose a failed request. The direct-image response behavior and request format are documented in the ScreenshotEngine quickstart and code examples. Confirm that the endpoint and fields are still supported before using them in a deployed script.

Screenshot API: POST JSON

Screenshot API documents this POST form. Its API also accepts GET parameters and supports PNG, JPEG, WebP, and PDF; consult its documentation for available viewport, full-page, advanced, and batch options:

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
export SCREENSHOT_API_KEY="YOUR_API_KEY"
curl --fail-with-body --request POST "https://api.screenshot-api.org/api/v1/screenshot" 
  --header "Authorization: Bearer $SCREENSHOT_API_KEY" 
  --header "Content-Type: application/json" 
  --data '{"url":"https://example.com","format":"png","fullPage":false}' 
  --output shot.png

Do not assume this response is raw image data: Screenshot API documents JSON/URL responses, so verify the response shape and use its documented retrieval flow if the POST returns JSON rather than image bytes. See Screenshot API’s REST documentation.

Safer credentials and URL handling

  • Keep keys out of source files. Read them from an environment variable or your deployment platform’s secret store. Avoid committing real keys to version control.
  • Prefer authorization headers when available. A key in a query string can be exposed in request logs or other records. Use the provider’s documented header authentication method where possible.
  • Quote shell values. Quote URLs and headers so shell characters do not become syntax. Use --data-urlencode for GET parameters containing a target URL, especially if the target itself has a query string or spaces.
  • Protect local output. Choose a controlled output path and avoid overwriting a valuable file unintentionally. In automated jobs, use a unique name or a temporary directory.

An environment variable avoids hard-coding a secret in the script, but it is not a complete secret-management system: processes and logs may expose environment values in some setups. Limit access to the account and runtime that need the key, and rotate it if it is exposed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Handle binary responses and HTTP failures correctly

Use HTTP status as the first success check; a file named shot.png might contain an error response rather than an image. curl --fail-with-body is useful in scripts and CI: it exits unsuccessfully for HTTP error responses while preserving the body for inspection. Do not pipe image bytes through text-processing tools such as sed or grep.

For a small manual run, inspect curl’s exit status:

if curl --fail-with-body -G "https://screenshot-api.net/v1/screenshot" 
  -H "Authorization: Bearer $SCREENSHOT_API_KEY" 
  --data-urlencode "url=https://example.com" 
  -o shot.png; then
  printf 'Capture saved to shot.pngn'
else
  printf 'Capture request failed; inspect the response and curl error above.n' >&2
  exit 1
fi

This checks whether curl completed successfully and received a non-error HTTP status. It does not prove that the returned bytes form a valid image or that the rendered page contains the content you expected. For robust automation, also validate the output with an image or file-inspection tool available in your environment, and retain enough error information to diagnose failures without logging secrets.

Capture a full webpage from the command line

“Full page” can refer to rendering beyond the initial viewport, while a viewport-height capture shows only the visible screen area. Providers use different names and semantics for this setting: the examples above use height:"full" for ScreenshotEngine and fullPage for Screenshot API. Use the exact field supported by your provider, and check whether it captures a long page, expands lazy-loaded content, or imposes page-size limits; those details are not established uniformly across these APIs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For long or dynamic pages, the page may need time to render before capture. If the API exposes wait conditions, selector waits, or other rendering controls, follow its documentation and choose a condition tied to the content you need. A fixed delay can be simple but may waste time or still finish before a slow page is ready. Do not add unsupported parameters and assume they will work.

Compare APIs by the response and controls you need

When selecting a hosted screenshot service for a Bash workflow, compare concrete contract details rather than just the example command:

  • Authentication: Does the API accept a bearer token in a header, a query parameter, or both?
  • HTTP method: Are GET and POST both supported, and which options belong to each?
  • Response shape: Does success return raw image bytes, a PDF, or JSON containing a URL or job result? What does an error return?
  • Rendering controls: Are viewport dimensions, full-page capture, and any required wait behavior documented?
  • Formats and workload: Which of PNG, JPEG, WebP, and PDF are available? Is batch capture documented if you need it?
  • Failure handling: Are status codes and error bodies described well enough for a script to distinguish a failed capture from an image?

For example, ScreenshotEngine documents direct image bytes on success and JSON errors; Screenshot API documents JSON/URL responses and batch capture; Screenshot API.net documents a GET that returns raw image bytes and a JSON /v1/capture mode. These are provider-documented behaviors, not a guarantee that every endpoint or option remains unchanged; verify the current API contract before deployment.

Troubleshooting Bash screenshot requests

401 or 403 response

Check that the environment variable is set in the same shell that runs curl, that the key is valid for the service, and that the authorization scheme matches its documentation. A missing variable can produce a syntactically valid but empty bearer token. Never paste a live key into a shared terminal transcript or support message.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

The output file is JSON or unreadable

The service may return JSON for this endpoint, including an error or a URL to a separately hosted capture, rather than image bytes. Check the HTTP status and response body, then follow the documented response flow. Confirm that the endpoint and method match the example and that the requested format is supported.

curl reports a URL or quoting error

Wrap shell arguments in quotes and pass the target through --data-urlencode for GET requests. If the target URL contains an ampersand and is not quoted, the shell may treat it as a control operator before curl receives it.

The page is incomplete or blank

A screenshot API renders a page remotely, so a successful HTTP request does not guarantee that the target page finished rendering as intended. Check that the target is publicly reachable from the service, that its content is not gated behind a login or bot check, and that you have chosen the correct viewport or full-page option. If documented wait controls exist, use one appropriate to the page’s content.

The request fails in CI or takes too long

Check the reported HTTP status and error body, the network access available to the runner, and the provider’s current timeout and limits. Keep the output binary-safe and set a client timeout appropriate to your workflow if the API documents expected response times. Retry only failures that are plausibly transient, and avoid uncontrolled retry loops that can multiply requests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

With ScreenshotNeo, Bash can call a single GET endpoint and write the response to a file. The API returns a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo documentation for request options and current behavior.

export SCREENSHOTNEO_API_KEY="YOUR_API_KEY"
curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key="$SCREENSHOTNEO_API_KEY" 
  --data-urlencode url=https://example.com 
  -o shot.webp

ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses include X-Page-Verdict and X-Billed headers. Its MCP server provides screenshot tools for AI agents, including Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Can a Bash script capture a page that requires a login?

Only if the provider supports the required authentication or session setup and its policy allows access. A public URL alone does not grant access to a private page.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does curl itself render a webpage?

No. In this workflow, curl sends the request; the screenshot API performs the remote page rendering and returns the result.

Can I use a screenshot API to create a PDF from Bash?

Yes, if the provider supports PDF output. Check its documented format parameter and whether the endpoint returns the PDF bytes directly or a JSON result.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.