Usage: Initate a POST request with the following parameters as JSON:
{
"api_key": "your-api-key", // Required. Your API key
"url": "http://example.com/", // The URL of the page of interest, OR
"content": "<html>...</html>", // The raw HTML content of the page of interest, OR
"pages": [{"url": "http://example.com/"}, {"content": "..."}], // An array of pages to stitch together. PDF only.
"format": "pdf|jpg|png", // The format of the output. Defaults to PNG.
"viewport_w": 1280, // Optional. Width of the capture viewport in pixels
"viewport_h": 800, // Optional. Height of the capture viewport in pixels
"viewport_scale": 1.0, // Optional. Viewport scale factor, i.e. device pixel ratio.
"php_sess_name": "PHPSESSID", // Optional. Include if screenshot is behind authentication.
"php_sess_id": "aBcDeF1234567890", // Optional. Include if screenshot is behind authentication.
"php_sess_domain": "example.com", // Optional. Include if screenshot is behind authentication. Also used as cookie domain.
"timer": "200|'callback'", // Optional. # of milliseconds to wait. 'callback' waits until callback selector element appears on page (max 60s)
"callback_selector": "#myelement", // Optional. CSS selector of element to wait for before capturing. Defaults to #phantom-page-ready.
"cookies": {"mycookie": "myvalue"}, // Optional. JSON object: key / value store of cookies the server should use.
"pdf_page_size": "A4", // Optional. PDF only. Size of output page.
"scale": 1.0, // Optional. PDF only. Must be between 0.1 and 2. Scale the web page.
"auth_username": "myuser", // Optional. Basic auth username.
"auth_password": "mypass", // Optional. Basic auth password.
"navigation_timeout": 30000, // Optional. Timeout in milliseconds for page navigation.
"batch_size": 10, // Optional. Max number of pages to process in parallel. Defaults to 4.
"pdf_header": "<div>...</div>", // Optional. PDF only. HTML content to be used as header on each page.
"pdf_footer": "<div>...</div>", // Optional. PDF only. HTML content to be used as footer on each page.
}
<?php
$post_data = [
"apiKey": "your-api-key",
'url' => 'https://mysite.com/screenshot/this/page',
'format' => 'pdf',
'viewport_w' => 1280,
'viewport_h' => 800,
'php_sess_name' => session_name(),
'php_sess_id' => session_id(),
'php_sess_domain' => $_SERVER['SERVER_NAME'],
'timer' => 200,
'cookies' => json_encode(['device_token' => 'abcdef123456'])
];
// Close the session so the session doesn't block Shuttershot from accessing the page.
session_write_close();
// Set up curl for the request.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://shuttershotnode.zingstudios.com",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 60,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($post_data),
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
throw new \Exception("cURL Error #:" . $err);
} else {
return $response;
}