Quick Start (GET example)

Use GET to capture a screenshot with query parameters:

<?php
$endpoint = "https://api.screenshotmax.com/v1/screenshot";
$params = http_build_query([
  "access_key" => "YOUR_ACCESS_KEY",
  "url" => "https://example.com",
  "format" => "png"
]);
$url = $endpoint . '?' . $params;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

if (curl_errno($ch)) {
  echo "Request failed: " . curl_error($ch);
} else {
  file_put_contents("screenshot.png", $response);
  echo "Image saved to screenshot.png\\n";
}

curl_close($ch);
?>

POST Example

Use POST when your data is long or includes special characters:

<?php
$endpoint = "https://api.screenshotmax.com/v1/screenshot";

$payload = json_encode([
  "access_key" => "YOUR_ACCESS_KEY",
  "url" => "https://example.com",
  "format" => "png"
]);

$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

$response = curl_exec($ch);

if (curl_errno($ch)) {
  echo "Request failed: " . curl_error($ch);
} else {
  file_put_contents("screenshot.png", $response);
  echo "Image saved to screenshot.png\\n";
}

curl_close($ch);
?>

Secured with HMAC Signature

For signed requests, use your secret_key to generate a signature:

<?php
$access_key = "YOUR_ACCESS_KEY";
$secret_key = "YOUR_SECRET_KEY";

$query = [
  "access_key" => $access_key,
  "url" => "https://example.com",
  "format" => "png"
];

// 1. Build query string without access_key or signature
$query_string = http_build_query($query);

// 2. Generate signature from query string only
$signature = hash_hmac("sha256", $query_string, $secret_key);

// 3. Append signature to query
$query["signature"] = $signature;

$endpoint = "https://api.screenshotmax.com/v1/screenshot";
$final_url = $endpoint . '?' . http_build_query($query);

// 4. Perform GET request
$ch = curl_init($final_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

if (curl_errno($ch)) {
  echo "Request failed: " . curl_error($ch);
} else {
  file_put_contents("screenshot.png", $response);
  echo "Signed request successful. Screenshot saved.\n";
}

curl_close($ch);
?>

Optional: PHP Wrapper Class

Reuse ScreenshotMAX with a simple OOP class:

<?php
class ScreenshotMAXClient {
  private $access_key;
  private $secret_key;
  private $endpoint;

  public function __construct($access_key, $secret_key, $endpoint = "https://api.screenshotmax.com/v1/screenshot") {
    $this->access_key = $access_key;
    $this->secret_key = $secret_key;
    $this->endpoint = $endpoint;
  }

  public function capture($url, $format = "png") {
    $body = json_encode([
      "url" => $url,
      "format" => $format
    ]);

    $ch = curl_init($this->endpoint);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'Content-Type: application/json',
      "X-Access-Key: {$this->access_key}",
    ]);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

    $response = curl_exec($ch);
    if (curl_errno($ch)) {
      throw new Exception("Request failed: " . curl_error($ch));
    }
    curl_close($ch);
    return $response;
  }
}

// Usage
$client = new ScreenshotMAXClient("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY");
file_put_contents("screenshot.png", $client->capture("https://example.com"));
echo "Image saved to screenshot.png\\n";
?>

Next Steps

  • Explore other API options like HTML to PDF, animated screenshots, or web scraping.
  • Create scheduled recurring screenshots via Scheduled Tasks API

Support

For questions, issues, or feature requests, please contact our support team at support@screenshotmax.com.