How to screenshot Indian government websites with ApiFlash
Capture an Indian government webpage with ApiFlash: configure full-page and viewport shots, wait for dynamic content, and troubleshoot access errors.
To screenshot an Indian government webpage with ApiFlash, send a GET request to https://api.apiflash.com/v1/urltoimage with your API key and the complete target URL, including https://. Add options such as full_page=true or format=png to control the capture. The default response is image data; use response_type=json when you need JSON containing links to generated files.
This is a general URL screenshot workflow; ApiFlash does not document a special Indian government website mode. No specific government page is guaranteed to be reachable or render successfully. Start with the exact public page address you intend to document.
1. Prepare the target URL and API key
- Copy the full URL of the public page you are authorized to capture, including its scheme, such as
https://example.gov.in/department/page. - Obtain an ApiFlash access key through ApiFlash. Do not publish the key or place it in browser-delivered frontend code. For a public-facing application, call ApiFlash from your server or use a proxy pattern from its guides.
- URL-encode parameter values when constructing a URL manually. HTTP clients generally encode query parameters for you.
A minimal request has this shape:
https://api.apiflash.com/v1/urltoimage?access_key=YOUR_ACCESS_KEY&url=https%3A%2F%2Fexample.gov.in
Replace the placeholder with your key and the target with the actual page URL. The endpoint returns the image bytes by default.
2. Capture a page with cURL
This saves a full-page PNG. Replace the sample URL and keep the access key out of source control; an environment variable avoids putting it directly in the command history.
export APIFLASH_ACCESS_KEY='YOUR_ACCESS_KEY'
curl --fail --show-error --silent --get 'https://api.apiflash.com/v1/urltoimage' \
--data-urlencode "access_key=$APIFLASH_ACCESS_KEY" \
--data-urlencode 'url=https://example.gov.in/' \
--data-urlencode 'full_page=true' \
--data-urlencode 'format=png' \
--output government-page.png
--fail makes cURL return a failure for HTTP error responses rather than saving an error body as if it were an image. To inspect response headers for quota information, add --dump-header response-headers.txt.
3. Capture a page with Python
Install Requests with python -m pip install requests. This example checks the HTTP status before writing the returned image.
import os
import requests
api_key = os.environ["APIFLASH_ACCESS_KEY"]
params = {
"access_key": api_key,
"url": "https://example.gov.in/",
"full_page": "true",
"format": "png",
}
response = requests.get(
"https://api.apiflash.com/v1/urltoimage",
params=params,
timeout=120,
)
response.raise_for_status()
with open("government-page.png", "wb") as image_file:
image_file.write(response.content)
Use a timeout suitable for your workload. For a production service, also catch request exceptions and HTTP errors, and avoid logging the full request URL because it contains the key.
4. Capture a page with Node.js
This example uses the built-in fetch available in current Node.js releases. It writes the binary response to a PNG file and reports non-success status codes.
import { writeFile } from "node:fs/promises";
const params = new URLSearchParams({
access_key: process.env.APIFLASH_ACCESS_KEY,
url: "https://example.gov.in/",
full_page: "true",
format: "png",
});
const response = await fetch(
`https://api.apiflash.com/v1/urltoimage?${params}`,
{ signal: AbortSignal.timeout(120_000) },
);
if (!response.ok) {
throw new Error(`ApiFlash returned HTTP ${response.status}: ${await response.text()}`);
}
await writeFile("government-page.png", Buffer.from(await response.arrayBuffer()));
Set the environment variable before running the script. Do not expose this server-side key in code shipped to a browser.
5. Choose capture settings
ApiFlash documents these parameters for controlling the capture. Exact plan availability can affect whether a feature is accepted; a 403 can mean the current plan does not support a requested option.
| Need | Setting | Behavior and caveat |
|---|---|---|
| Entire page | full_page=true |
Captures the full page; height is ignored when full-page capture is enabled. |
| Viewport dimensions | width, height |
Defaults are 1920 × 1080. Each documented maximum is 16,350 pixels, and their product must not exceed 33,177,600 pixels. |
| Image format | format=png, jpeg, or webp |
Choose PNG for crisp text and lossless output; JPEG or WebP may reduce file size. quality applies to JPEG and WebP. |
| Wait for a known element | wait_for |
Provide a CSS selector for content that appears late, such as a results panel. The selector must exist for the capture to proceed as intended. |
| Choose page readiness | wait_until |
Supported values include dom_loaded, page_loaded, and network_idle. ApiFlash defaults to network idle. |
| Short fixed pause | delay |
Waits for a specified delay up to 10 seconds. Prefer readiness controls when they describe the page more reliably. |
| Trigger lazy content | scroll_page=true |
Scrolls the page before capture, which can trigger animations or lazy-loaded elements. |
| Language preference | accept_language |
Requests a language preference. The site may still choose language based on its own logic. |
| JSON metadata and links | response_type=json |
Returns a JSON document with links to generated files instead of returning only image bytes. |
| Cache behavior | ttl, fresh=true |
Identical parameter sets may use a cached screenshot. Set a TTL to control caching; use fresh=true to request a new capture. |
Viewport versus full-page capture
Use a viewport when you need a reproducible screen-sized view, such as the initial view a reader sees. Use full_page=true when the record must include content below the fold. Full-page output can be tall and large; the viewport area limit above does not imply that every exceptionally long page will be practical to capture or share as one image.
Wait for the right content
Use dom_loaded for pages where the required markup is present early, page_loaded when the page’s load event is sufficient, and the default network_idle when the page settles after its network activity. For a page that continues background requests or renders a specific panel late, try a selector with wait_for. A fixed delay can help diagnose timing, but it is less precise and is capped at 10 seconds.
Language and authenticity
Use the exact page URL and, when useful, set accept_language to a language preference such as en or hi. India’s government website guidelines treat a web address as a strong indicator of whether a site is official, not a guarantee of reachability or successful rendering. Verify the page address independently before relying on a screenshot as evidence.
6. Handle access, dynamic pages, and output safely
Government pages may use bot protection, load content after the initial document, or require authorization. ApiFlash’s FAQ says Cloudflare-like protections can block its capture service and strict protections may continue to block it. A proxy is mentioned as a possible option, but its effectiveness depends on the protection. Do not treat a failed capture as permission to bypass access controls. For authenticated content, only use headers or cookies when you are authorized to access and capture that content.
For audit or archival use, preserve the requested URL, capture time, response status, and relevant capture parameters alongside the image. If the page is localized, dynamic, or updated frequently, note the selected language and whether a cached result was permitted. A screenshot records what the rendering service received; it does not by itself establish that the page is authentic, complete, or current.
7. Troubleshoot common errors
| Symptom or status | Likely cause | What to do |
|---|---|---|
400 |
Invalid parameters or a target URL that cannot be captured. | Check parameter names and values, ensure the target URL includes http:// or https://, and encode query values correctly. |
401 |
Invalid or revoked access key. | Confirm the key is current, is sent as access_key, and has no accidental whitespace. Rotate a key if it was exposed. |
402 |
Monthly quota exceeded. | Check quota headers or the quota endpoint, then wait for reset or change the plan according to your needs. |
403 |
The plan does not support a requested feature. | Remove or replace the unsupported option, or confirm the feature is available on your plan. |
429 |
Request rate or burst limit exceeded. | Back off and retry with jitter; limit concurrency. ApiFlash documents 20 requests per second with a burst size of 400. |
500 |
Capture failed and was returned as an API error. | Retry a transient failure with backoff, verify the URL is reachable, simplify options, and inspect whether the site blocks automated capture. |
| Image is blank or incomplete | Content was not ready, blocked, lazy-loaded, or dependent on a browser interaction. | Try wait_for for the required element, adjust wait_until, or use scroll_page=true. If bot protection blocks capture, respect the site’s access controls. |
| Text or layout differs from local browser | Capture runs in Chrome on Linux; available system fonts may differ from Windows or macOS. | Compare at the same viewport and language, and account for platform font differences when interpreting line breaks and layout. |
| Repeated failure is throttled | ApiFlash limits identical failed captures to five requests per hour. | Do not loop the same failing request. Correct the URL or options first, then retry deliberately. |
| Old screenshot returned | Matching request may have hit the cache. | Set an appropriate ttl or request fresh=true for a new capture. |
8. Performance, reliability, and cost considerations
- Request rate: ApiFlash documents 20 requests per second and a burst size of 400. Apply a bounded queue and exponential backoff with jitter when processing batches; avoid synchronized retries.
- Cache: Identical requests may be served from cache. Caching can avoid unnecessary recaptures when a page and settings have not changed; use
fresh=truewhen freshness matters. - Image size: Full-page and high-resolution captures create larger responses. Select only the dimensions and format needed, and consider JPEG or WebP with a suitable quality when smaller files matter.
- Timeouts: Dynamic pages and long full-page captures can take longer. Set a client timeout that reflects the job and handle timeout errors explicitly rather than treating them as valid images.
- Quota tracking: Successful responses may include
X-Quota-Limit,X-Quota-Remaining, andX-Quota-Reset. Monitor these or use the quota endpoint before scheduling large jobs. - Price: The research materials do not specify ApiFlash pricing, so check its current plan and quota details before estimating production cost.
- Reliability: Bot protection, unavailable pages, failed loads, or page changes can prevent a useful capture. Treat screenshots as outputs to validate, and record enough request metadata to reproduce a capture.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request returns an image or PDF; see the API documentation for configuration. For example, this cURL request captures the same kind of public page:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.gov.in -o shot.webp
ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; each cleanup step can be turned off. Bot checks, blank pages, failed loads, and cache hits cost nothing, and response headers say which page verdict applied and whether the capture was billed. Its MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.
Create a free ScreenshotNeo account to get 1,000 screenshots a month with no card.
FAQ
Does ApiFlash have an India-specific government-site setting?
The reviewed documentation describes a general URL capture API, not a special mode for Indian government domains.
Can I capture a page behind a login?
Only capture it if you are authorized. ApiFlash describes headers or cookies for authenticated pages; treat those credentials as secrets and follow the site’s access rules.
Will a screenshot prove a government page is genuine?
No. A screenshot shows rendered content. Check the official address and source independently; a domain clue is not a guarantee.
Can I use the returned image directly in an application?
Yes, but keep the ApiFlash key on the server side and return or store the resulting image through your application. Avoid exposing a secret key in a public page URL.


