This is an outdated version of the Screenshot API. Please refer to Latest Version Documentation for the greatest functionality.
Restpack Screenshot API is an easy to use RESTful web service that can capture screenshots of live web pages and deliver the results in several formats. The service sits on a fully functional browser rendering engine with rich html / css / js capabilities.
Here are some code samples you can use. Don't forget to obtain a token here.
http --form POST https://restpack.io/api/screenshot/v3/capture \
x-access-token:TOKEN \
url=http://google.com \
json=true
curl --request POST \
--url https://restpack.io/api/screenshot/v3/capture \
--header 'x-access-token: TOKEN' \
--data 'url=http%3A%2F%2Fgoogle.com&json=true'
var request = require("request");
var options = { method: 'POST',
url: 'https://restpack.io/api/screenshot/v3/capture',
headers: { 'x-access-token': 'TOKEN' },
form: { url: 'http://google.com', json: true } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
require 'uri'
require 'net/http'
url = URI("https://restpack.io/api/screenshot/v3/capture")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["x-access-token"] = 'TOKEN'
request.body = "url=http%3A%2F%2Fgoogle.com&json=true"
response = http.request(request)
puts response.read_body
import http.client
conn = http.client.HTTPSConnection("restpack.io")
payload = "url=http%3A%2F%2Fgoogle.com&json=true"
headers = { 'x-access-token': "TOKEN" }
conn.request("POST", "/api/screenshot/v3/capture", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://restpack.io/api/screenshot/v3/capture"
payload := strings.NewReader("url=http%3A%2F%2Fgoogle.com&json=true")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-access-token", "TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://restpack.io/api/screenshot/v3/capture",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "url=http%3A%2F%2Fgoogle.com&json=true",
CURLOPT_HTTPHEADER => array(
"x-access-token: TOKEN"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
var client = new RestClient("https://restpack.io/api/screenshot/v3/capture");
var request = new RestRequest(Method.POST);
request.AddHeader("x-access-token", "TOKEN");
request.AddParameter("undefined", "url=http%3A%2F%2Fgoogle.com&json=true", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
HttpResponse<String> response = Unirest.post("https://restpack.io/api/screenshot/v3/capture")
.header("x-access-token", "TOKEN")
.body("url=http%3A%2F%2Fgoogle.com&json=true")
.asString();
You can find detailed usage information below.
With each API call, you must provide an authentication token. To create a new access token please refer to user tokens page on your account dashboard.
You will need to use your Direct Access Token for simple API calls.
You can either provide the access token within the querystring or as a header.
access_token
querystring parameter. As in https://restpack.io/api/screenshot/v3/capture?access_token={TOKEN}
X-Access-Token
header.Access token errors are represented in 4xx
class HTTP errors.
By default, the API returns the raw image itself. This is the easiest way to consume the API. You can stream the result back to a file, to a web request or any other storage service.
Meanwhile, it is possible to receive a JSON response using mode: json
parameter.
When you request a JSON response, API will return a JSON object with a publicly accesible URL to the resulting screenshot image. You can use this image directly on your websites or access the file from this URL and save it elsewhere. Using this URL is not counted against your API call limits and it is being hosted over our CDN servers.
JSON
responses simply contain an image
URL and a cached
field to indicate if the image is being served from cache:
{
"image": "http://cdn.restpack.io/...",
"cached": true
}
In order to capture a screenshot, you simply need to invoke a GET request on the following URL.
All parameters should be passed in querysting.
It is required to provide one of url
or html
parameters as the document source.
urlurl | The URL of web page, including the protocol that you want to capture. Example: http://example.com |
htmlstring | Raw HTML string of a page that you want to capture. Example: <p>Test</p> |
access_tokenstring | Your personal access token for API access. Example: XXXXXXXX |
jsonboolean | Return a JSON response with the resulting image's URL instead of the image itself. Default: false |
modeenum | Capturing mode. Please see below for details. Default: fullpagePattern: fullpage | viewport | element |
formatenum | Preferred image output format. If you need a raw html string you can pass html as format Default: pngPattern: jpg | png | pdf | html |
widthinteger | Preferred viewport width in pixels. Default: 1280Min: 320Max: 2000 |
heightinteger | Preferred viewport height in pixels. Default: 1024Min: 160 |
thumbnail_widthinteger | In case you want a thumbnail image, provide a preferred width. Min: 10Max: 3000 |
thumbnail_heightinteger | Preferred thumbnail height, requires thumbnail_width to be set, unbounded if omitted. Min: 10Max: 3000 |
cssstring | Additional CSS string to be injected into the page before render. |
jsstring | Additional JS string to be injected into the page before render. |
delaynumber | Time in milliseconds to delay capture after page load. Default: 500Max: 10000 |
ttlnumber | Time in milliseconds for the resulting image to be cached for further requests. Default: 1 dayMax: 1 week |
freshboolean | Force rendering a new screenshot disregarding the cache status. Default: false |
user_agentstring | Custom user-agent header string for the web request. Default: Chrome Compatible User Agent |
headersstring | Additional headers seperated with newline Example: X-Test: header\nAccept-Type: html |
element_selectorstring | A CSS selector to be used with element rendering mode. |
retinaboolean | Generate retina sized screen capture (2x device pixel ratio). Default: false |
emulate_mediaenum | Force CSS media emulation for print or screen. Default: screenPattern: screen | print |
allow_failedboolean | By default, any response from remote server outside http 200-299 status codes generates an error. If you wish to capture error pages, pass true. Default: false |
waitenum | Wait until window load event fires or network becomes idle before capturing the page. By default we wait for the load event but if you are capturing pages with async content / lazy loaded images etc, waiting for network might work better. Third option is dom, which basically waits for domready event on the main window. Default: loadPattern: load | network | dom |
shutterstring | Wait until a DOM element matching the provided css selector becomes present on the page. You can control when you want to capture the page using this parameter. The process times out after 10 seconds. Example: h1.someclass |
POST mode accepts the exact same parameters but you need to use a JSON or url encoded body. access_token
parameter still needs to be passed in the querystring or via x-access-token
header.
http --form POST https://restpack.io/api/screenshot/v3/capture \
x-access-token:TOKEN \
url=http://google.com \
json=true
curl --request POST \
--url https://restpack.io/api/screenshot/v3/capture \
--header 'x-access-token: TOKEN' \
--data 'url=http%3A%2F%2Fgoogle.com&json=true'
var request = require("request");
var options = { method: 'POST',
url: 'https://restpack.io/api/screenshot/v3/capture',
headers: { 'x-access-token': 'TOKEN' },
form: { url: 'http://google.com', json: true } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
require 'uri'
require 'net/http'
url = URI("https://restpack.io/api/screenshot/v3/capture")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["x-access-token"] = 'TOKEN'
request.body = "url=http%3A%2F%2Fgoogle.com&json=true"
response = http.request(request)
puts response.read_body
import http.client
conn = http.client.HTTPSConnection("restpack.io")
payload = "url=http%3A%2F%2Fgoogle.com&json=true"
headers = { 'x-access-token': "TOKEN" }
conn.request("POST", "/api/screenshot/v3/capture", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://restpack.io/api/screenshot/v3/capture"
payload := strings.NewReader("url=http%3A%2F%2Fgoogle.com&json=true")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-access-token", "TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://restpack.io/api/screenshot/v3/capture",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "url=http%3A%2F%2Fgoogle.com&json=true",
CURLOPT_HTTPHEADER => array(
"x-access-token: TOKEN"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
var client = new RestClient("https://restpack.io/api/screenshot/v3/capture");
var request = new RestRequest(Method.POST);
request.AddHeader("x-access-token", "TOKEN");
request.AddParameter("undefined", "url=http%3A%2F%2Fgoogle.com&json=true", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
HttpResponse<String> response = Unirest.post("https://restpack.io/api/screenshot/v3/capture")
.header("x-access-token", "TOKEN")
.body("url=http%3A%2F%2Fgoogle.com&json=true")
.asString();
{
"image": "http://cdn.restpack.io/...",
"cached": true
}
This is the default operation mode of the API. You can control the width of captured viewport using width
parameter. height
parameter sets the viewport height and might change how sites behave.
For example, if you wish to capture with an iPhone 6 viewport size, the width
parameter should be set 375
and width 667
. While using mobile viewports, don’t forget to also provide a user agent header.
The engine will figure out the complete height of the page and return the entire screen capture. height
parameter itself does not restrict the final image size. If the page height is larger than 16.000 pixels, the render will be restricted to the first 16.000 pixels.
Note that using png
format with large pages may yield huge files and degrade rendering performance. We suggest using jpg
files in case you are expecting renders to be big.
http GET 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&width=1280&format=jpg' \
x-access-token:TOKEN
curl --request GET \
--url 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&width=1280&format=jpg' \
--header 'x-access-token: TOKEN'
var request = require("request");
var options = { method: 'GET',
url: 'https://restpack.io/api/screenshot/v3/capture',
qs: { url: 'http://google.com', width: '1280', format: 'jpg' },
headers: { 'x-access-token': 'TOKEN' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
require 'uri'
require 'net/http'
url = URI("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&width=1280&format=jpg")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["x-access-token"] = 'TOKEN'
response = http.request(request)
puts response.read_body
import http.client
conn = http.client.HTTPSConnection("restpack.io")
headers = { 'x-access-token': "TOKEN" }
conn.request("GET", "/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&width=1280&format=jpg", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&width=1280&format=jpg"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-access-token", "TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&width=1280&format=jpg",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"x-access-token: TOKEN"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
var client = new RestClient("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&width=1280&format=jpg");
var request = new RestRequest(Method.GET);
request.AddHeader("x-access-token", "TOKEN");
IRestResponse response = client.Execute(request);
HttpResponse<String> response = Unirest.get("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&width=1280&format=jpg")
.header("x-access-token", "TOKEN")
.asString();
This mode restricts the rendered image to supplied viewport size (1280x1024
by default). You can think of this as an actual screen capture of a desktop with full screen browser. Whatever content outside the viewport will not be captured.
Note that this is not to create specific size thumbnails of web pages. For that purpose please check Thumbnails section. When you specify a small viewport, websites might degrade to mobile sites, response web pages will respond by shrinking and if the content is smaller than the viewport, you might not receive an image in exact size of the viewport.
http GET 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=viewport&width=640&height=480' \
x-access-token:TOKEN
curl --request GET \
--url 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=viewport&width=640&height=480' \
--header 'x-access-token: TOKEN'
var request = require("request");
var options = { method: 'GET',
url: 'https://restpack.io/api/screenshot/v3/capture',
qs:
{ url: 'http://google.com',
mode: 'viewport',
width: '640',
height: '480' },
headers: { 'x-access-token': 'TOKEN' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
require 'uri'
require 'net/http'
url = URI("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=viewport&width=640&height=480")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["x-access-token"] = 'TOKEN'
response = http.request(request)
puts response.read_body
import http.client
conn = http.client.HTTPSConnection("restpack.io")
headers = { 'x-access-token': "TOKEN" }
conn.request("GET", "/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=viewport&width=640&height=480", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=viewport&width=640&height=480"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-access-token", "TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=viewport&width=640&height=480",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"x-access-token: TOKEN"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
var client = new RestClient("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=viewport&width=640&height=480");
var request = new RestRequest(Method.GET);
request.AddHeader("x-access-token", "TOKEN");
IRestResponse response = client.Execute(request);
HttpResponse<String> response = Unirest.get("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=viewport&width=640&height=480")
.header("x-access-token", "TOKEN")
.asString();
If you wish to capture a specific element within the page (maybe you want to have a chart captured, or the list of latest headlines, etc.) you can specify a CSS Selector for that element using element_selector
parameter and selecting mode: element
. In this mode, the page will be rendered in specified viewport size (1280x1024
by default) but only the rectangle of requested element will be captured.
If the element is not found, you will receive an error.
http GET 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=element&element_selector=%23container%20.chart' \
x-access-token:TOKEN
curl --request GET \
--url 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=element&element_selector=%23container%20.chart' \
--header 'x-access-token: TOKEN'
var request = require("request");
var options = { method: 'GET',
url: 'https://restpack.io/api/screenshot/v3/capture',
qs:
{ url: 'http://google.com',
mode: 'element',
element_selector: '#container .chart' },
headers: { 'x-access-token': 'TOKEN' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
require 'uri'
require 'net/http'
url = URI("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=element&element_selector=%23container%20.chart")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["x-access-token"] = 'TOKEN'
response = http.request(request)
puts response.read_body
import http.client
conn = http.client.HTTPSConnection("restpack.io")
headers = { 'x-access-token': "TOKEN" }
conn.request("GET", "/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=element&element_selector=%23container%20.chart", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=element&element_selector=%23container%20.chart"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-access-token", "TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=element&element_selector=%23container%20.chart",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"x-access-token: TOKEN"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
var client = new RestClient("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=element&element_selector=%23container%20.chart");
var request = new RestRequest(Method.GET);
request.AddHeader("x-access-token", "TOKEN");
IRestResponse response = client.Execute(request);
HttpResponse<String> response = Unirest.get("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&mode=element&element_selector=%23container%20.chart")
.header("x-access-token", "TOKEN")
.asString();
The API will return a full size render by default. If you want to generate smaller thumbnail images, provide a thumbnail_width
parameter. This will ensure that the resulting image will have the specified width.
If you omit the thumbnail_height
parameter, it will be autmatically determined according to specified width. If you also provide a thumbnail_height
then the image will be cropped to the strictly specified thumbnail size.
http GET 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&thumbnail_width=250&thumbnail_height=250' \
x-access-token:TOKEN
curl --request GET \
--url 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&thumbnail_width=250&thumbnail_height=250' \
--header 'x-access-token: TOKEN'
var request = require("request");
var options = { method: 'GET',
url: 'https://restpack.io/api/screenshot/v3/capture',
qs:
{ url: 'http://google.com',
thumbnail_width: '250',
thumbnail_height: '250' },
headers: { 'x-access-token': 'TOKEN' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
require 'uri'
require 'net/http'
url = URI("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&thumbnail_width=250&thumbnail_height=250")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["x-access-token"] = 'TOKEN'
response = http.request(request)
puts response.read_body
import http.client
conn = http.client.HTTPSConnection("restpack.io")
headers = { 'x-access-token': "TOKEN" }
conn.request("GET", "/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&thumbnail_width=250&thumbnail_height=250", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&thumbnail_width=250&thumbnail_height=250"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-access-token", "TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&thumbnail_width=250&thumbnail_height=250",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"x-access-token: TOKEN"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
var client = new RestClient("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&thumbnail_width=250&thumbnail_height=250");
var request = new RestRequest(Method.GET);
request.AddHeader("x-access-token", "TOKEN");
IRestResponse response = client.Execute(request);
HttpResponse<String> response = Unirest.get("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&thumbnail_width=250&thumbnail_height=250")
.header("x-access-token", "TOKEN")
.asString();
Restpack HTML to Screenshot API can generate JPG, PNG and PDF files. The default is PNG
with losless compression. The JPG
output provides the smaller sizes but has a fixed 80%
quality setting.
http GET 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&format=png' \
x-access-token:TOKEN
curl --request GET \
--url 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&format=png' \
--header 'x-access-token: TOKEN'
var request = require("request");
var options = { method: 'GET',
url: 'https://restpack.io/api/screenshot/v3/capture',
qs: { url: 'http://google.com', format: 'png' },
headers: { 'x-access-token': 'TOKEN' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
require 'uri'
require 'net/http'
url = URI("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&format=png")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["x-access-token"] = 'TOKEN'
response = http.request(request)
puts response.read_body
import http.client
conn = http.client.HTTPSConnection("restpack.io")
headers = { 'x-access-token': "TOKEN" }
conn.request("GET", "/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&format=png", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&format=png"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-access-token", "TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&format=png",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"x-access-token: TOKEN"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
var client = new RestClient("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&format=png");
var request = new RestRequest(Method.GET);
request.AddHeader("x-access-token", "TOKEN");
IRestResponse response = client.Execute(request);
HttpResponse<String> response = Unirest.get("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&format=png")
.header("x-access-token", "TOKEN")
.asString();
By default, capturing engine waits for the page load and then 2
more seconds for initial javascripts to settle their rendering. You can control this duration using delay
parameter (in milliseconds) from instantaneous to 10 seconds.
http GET 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&delay=5000' \
x-access-token:TOKEN
curl --request GET \
--url 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&delay=5000' \
--header 'x-access-token: TOKEN'
var request = require("request");
var options = { method: 'GET',
url: 'https://restpack.io/api/screenshot/v3/capture',
qs: { url: 'http://google.com', delay: '5000' },
headers: { 'x-access-token': 'TOKEN' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
require 'uri'
require 'net/http'
url = URI("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&delay=5000")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["x-access-token"] = 'TOKEN'
response = http.request(request)
puts response.read_body
import http.client
conn = http.client.HTTPSConnection("restpack.io")
headers = { 'x-access-token': "TOKEN" }
conn.request("GET", "/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&delay=5000", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&delay=5000"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-access-token", "TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&delay=5000",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"x-access-token: TOKEN"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
var client = new RestClient("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&delay=5000");
var request = new RestRequest(Method.GET);
request.AddHeader("x-access-token", "TOKEN");
IRestResponse response = client.Execute(request);
HttpResponse<String> response = Unirest.get("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&delay=5000")
.header("x-access-token", "TOKEN")
.asString();
The API caches captured screenshots up to a specified time period. If you request a screenshot of a previously cached web page, result will be provided from the cache. It is possible to control the duration of cache using ttl
parameter (in milliseconds)
In addition to setting a ttl
, it is possible to use fresh=true
prameter to invalidate cache and capture a new screenshot.
http GET 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&ttl=60000' \
x-access-token:TOKEN
curl --request GET \
--url 'https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&ttl=60000' \
--header 'x-access-token: TOKEN'
var request = require("request");
var options = { method: 'GET',
url: 'https://restpack.io/api/screenshot/v3/capture',
qs: { url: 'http://google.com', ttl: '60000' },
headers: { 'x-access-token': 'TOKEN' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
require 'uri'
require 'net/http'
url = URI("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&ttl=60000")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["x-access-token"] = 'TOKEN'
response = http.request(request)
puts response.read_body
import http.client
conn = http.client.HTTPSConnection("restpack.io")
headers = { 'x-access-token': "TOKEN" }
conn.request("GET", "/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&ttl=60000", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&ttl=60000"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-access-token", "TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&ttl=60000",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"x-access-token: TOKEN"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
var client = new RestClient("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&ttl=60000");
var request = new RestRequest(Method.GET);
request.AddHeader("x-access-token", "TOKEN");
IRestResponse response = client.Execute(request);
HttpResponse<String> response = Unirest.get("https://restpack.io/api/screenshot/v3/capture?url=http%3A%2F%2Fgoogle.com&ttl=60000")
.header("x-access-token", "TOKEN")
.asString();
While the service uses reasonable defaults for the request headers, you can customize them as you wish.
user_agent
parameter customizes the User-Agent
header.headers
parameter is the freeform one. You can pass any string containing headers seperated by \n
.echo '{ "url": "http://google.com", "json": true, user_agent: "MyBot 1/2", headers: "Cookie: name=value\nX-Custom-Header: custom" }' | \
http POST https://restpack.io/api/screenshot/v3/capture \
x-access-token:TOKEN
curl --request POST \
--url https://restpack.io/api/screenshot/v3/capture \
--header 'x-access-token: TOKEN' \
--data '{ "url": "http://google.com", "json": true, user_agent: "MyBot 1/2", headers: "Cookie: name=value\nX-Custom-Header: custom" }'
var request = require("request");
var options = { method: 'POST',
url: 'https://restpack.io/api/screenshot/v3/capture',
headers: { 'x-access-token': 'TOKEN' },
body: '{ "url": "http://google.com", "json": true, user_agent: "MyBot 1/2", headers: "Cookie: name=value\\nX-Custom-Header: custom" }' };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
require 'uri'
require 'net/http'
url = URI("https://restpack.io/api/screenshot/v3/capture")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["x-access-token"] = 'TOKEN'
request.body = "{ \"url\": \"http://google.com\", \"json\": true, user_agent: \"MyBot 1/2\", headers: \"Cookie: name=value\\nX-Custom-Header: custom\" }"
response = http.request(request)
puts response.read_body
import http.client
conn = http.client.HTTPSConnection("restpack.io")
payload = "{ \"url\": \"http://google.com\", \"json\": true, user_agent: \"MyBot 1/2\", headers: \"Cookie: name=value\\nX-Custom-Header: custom\" }"
headers = { 'x-access-token': "TOKEN" }
conn.request("POST", "/api/screenshot/v3/capture", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://restpack.io/api/screenshot/v3/capture"
payload := strings.NewReader("{ \"url\": \"http://google.com\", \"json\": true, user_agent: \"MyBot 1/2\", headers: \"Cookie: name=value\\nX-Custom-Header: custom\" }")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-access-token", "TOKEN")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://restpack.io/api/screenshot/v3/capture",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{ \"url\": \"http://google.com\", \"json\": true, user_agent: \"MyBot 1/2\", headers: \"Cookie: name=value\\nX-Custom-Header: custom\" }",
CURLOPT_HTTPHEADER => array(
"x-access-token: TOKEN"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
var client = new RestClient("https://restpack.io/api/screenshot/v3/capture");
var request = new RestRequest(Method.POST);
request.AddHeader("x-access-token", "TOKEN");
request.AddParameter("undefined", "{ \"url\": \"http://google.com\", \"json\": true, user_agent: \"MyBot 1/2\", headers: \"Cookie: name=value\\nX-Custom-Header: custom\" }", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
HttpResponse<String> response = Unirest.post("https://restpack.io/api/screenshot/v3/capture")
.header("x-access-token", "TOKEN")
.body("{ \"url\": \"http://google.com\", \"json\": true, user_agent: \"MyBot 1/2\", headers: \"Cookie: name=value\\nX-Custom-Header: custom\" }")
.asString();