API Documentation > Rest API > Create Website Screenshot with Rest API

Create website Screenshot with Rest API

Use this REST API to get the website Screenshot

HTTP GET/POST to Call

We support both of GET and POST method. To make a call, make an HTTP GET or POST request to api server to following URL.

http://api.page2images.com/restfullink

Quick Start

The most simple API looks like this:

http://api.page2images.com/restfullink?p2i_url=TARGET_URL&p2i_key=YOUR_API_KEY
Click this here to see the demo image

Parameters

Required Parameters

Parameter Default Description
{p2i_url} N/A URL of target page. Do not need to be encode.
Valid inputs:
www.google.com
google.com
http://www.google.com
https://www.google.com
{p2i_key} N/A The API key in your account. You can get it here.
Please use the Restful Key rather than Direct Link Key. Why?

Optional Parameters

Parameter Default Description
{p2i_device} 6 Our system can generate the screenshot for those smart phones and desktops. Please pass it to server as needed.
Following are devices we supported:
0 - iPhone4, 1 - iPhone5, 2 - Android, 3 - WinPhone, 4 - iPad, 5 - Android Pad, 6 - Desktop, 7 - iPhone6, 8 - iPhone6+
{p2i_size} N/A The screenshot file size you want to get. Not the screen size of device. If you want a big image, you need enlarge the width and height. If you need a small one, you need reduce the width and height. But it will take some more time to download a big image than a small one.
Format:
widthxheight e.g. 300x300

We predefined the size for those devices for most usage:
Mobile Phones: 320x480
Tablets: 512x384
Desktop: 640x400

Advanced information:
1) If you only know the fixed width or height of the images you want to get, you can just pass the width or height to us by following format: 512x0 or 0x512. We will resize the image to fit that width/height and make sure it is the biggest image we can generate.
2) The screenshot image will be resized to fit the width and height without stretching
{p2i_screen} null The screen size of device you want to simulate.
Format:
screen_widthxscreen_height e.g. 1024x768
We predefined the size for those devices for most usage:
Mobile: 320x480
Mobile iPhone5: 320x500
Mobile iPhone6: 375x667
Mobile iPhone6+: 414x736
Tablets: 1024x768
Desktop: 1280x800
Advanced information:
1) The screen size should be larger than image size.
{p2i_fullpage} 0 Set it to 1 if you need take screenshot of whole web page. Otherwise, it will only take the screenshot of first screen.
By default, it will auto scroll to the bottom of the page to load all necessary resources including those lazy load images.
We also have resolved the famous 100vh problem of puppeteer.
{p2i_callback} null It will take around 10-30 seconds to generate a website screenshot. If you want to us send a POST request to this URL when it finished. Please return 200 status code when you get the request.
How to create website screenshot with callback API
{p2i_imageformat} png png, jpg, pdf.
PNG format will be used to generate a high quality but large image. JPG will generate a normal quality but small image.
{p2i_scalefactor} 1 The screen scale factor use to generate the screenshot. The image size will multiply scale factor. Only p2i_engine=chrome support this feature. By default, p2i_engine is chrome.
{p2i_element} null A CSS selector. We will only take a screenshot of the first element matched by the given CSS selector. If there is no element match, it will report error. It should be URL encoded.

This feature will not be available when p2i_imageformat is PDF.

Only p2i_engine=chrome support this feature. By default, p2i_engine is chrome.
{p2i_quality} 90 The quality of the image. The quality of the image between 80 and 100. This only works with the jpeg format.
{p2i_wait} 0 How many seconds to wait after page loaded completed. From 0 seconds to a maximum of 25 seconds.
{p2i_refresh} 0 If it is 1, we will not use cache. But only can be refreshed after 5 minutes system generated it.
{p2i_useragent} null Sets the User-Agent of browser to emulate a special device when making screenshots. It should be URL encoded to be processed correctly. If you do not pass useragent, it will use the standard UA of the device you selected.
{p2i_accept_language} null Sets the Accept-Language header of request. You can simulate a special language of browser as needed. It will be very useful if you want to take screenshots for different languages of same website.
Only p2i_engine=chrome support this feature. By default, p2i_engine is chrome.
{p2i_headers} null A semicolon separated list of headers to be used when capturing the screenshot. Each header should be supplied as a key value pair and multiple pairs should be separated by a semicolon. The headers parameter value should be URL encoded to be processed correctly. For example, Header1=value1;Header2=value2 would have to be URL encoded into Header1%3Dvalue1%3BHeader2%3Dvalue2.

Only p2i_engine=chrome support this feature. By default, p2i_engine is chrome.

This feature only is available in "Advanced Plan" and above plans.

{p2i_cookies} null A string to set the browser cookies before taking screenshot. String should to be URL encoded to be processed correctly.

%5B%7B%22name%22%3A%221P_JAR%22%2C%22value%22%3A%222020-6-30-1%22%2C%22domain%22%3A%22.google.com%22%2C%22path%22%3A%22%2F%22%2C%22expires%22%3A1596074330%2C%22size%22%3A17%2C%22httpOnly%22%3Afalse%2C%22secure%22%3Atrue%2C%22session%22%3Afalse%7D%2C%7B%22name%22%3A%22NID%22%2C%22value%22%3A%22204%3Dksa4QpZF6pD0CHLS5uq2vAFJPVMBO6lVCyJqcZ-yZu8XDhq8pw1h-cx7vJe0ML-4U-uDk0Eqt90PxqfjLDDQKUgomo6_HM2UQFpJ1-5JTYzhRMfjujd1jVEYOb4GIZng4gyhxdNTBTCw7gl96FddEeA81fi2Vhx5Jx9abVjyHfE%22%2C%22domain%22%3A%22.google.com%22%2C%22path%22%3A%22%2F%22%2C%22expires%22%3A1609293530.567751%2C%22size%22%3A178%2C%22httpOnly%22%3Atrue%2C%22secure%22%3Atrue%2C%22session%22%3Afalse%2C%22sameSite%22%3A%22None%22%7D%5D

The length of the cookies string will be less than 16K.

Only p2i_engine=chrome support this feature. By default, p2i_engine is chrome.

This feature only is available in "Premium Plan" and above plans.

{p2i_css} null A CSS string to inject in the web page before token the screenshot. This CSS string should to be URL encoded to be processed correctly.
The length of the CSS string will be less than 16K.
If it is large than 16K, you can use a url here which points to the css file can be accesed from internet. For example, https://api.page2images.com/demo/gray.css. Please use HTTPS if you can. HTTP resources can not be used in HTTPS pages.

Only p2i_engine=chrome support this feature. By default, p2i_engine is chrome.

This feature only is available in "Advanced Plan" and above plans.

{p2i_initjs} null A JavaScript code to be injected into the page before send request to server. Cannot get any HTML elements in here. Usually use to set headers or cookies or environment variable.
The length of the JS string will be less than 16K.

Only p2i_engine=chrome support this feature. By default, p2i_engine is chrome.

This feature only is available in "Premium Plan" and above plans.

{p2i_onloadjs} null A JavaScript code to be injected into the page after onload completed event. Can access most of page HTML elements.
The length of the JS string will be less than 16K.

Only p2i_engine=chrome support this feature. By default, p2i_engine is chrome.

This feature only is available in "Premium Plan" and above plans.

{p2i_geo} null A string to specify the geo location information when website page call javascript method navigator.geolocation.getCurrentPosition. If client side use IP location to identify geo position, this feature will not work.
Format: latitude:longitude:accuracy. For example: "12.12:12.12:21"

Only p2i_engine=chrome support this feature. By default, p2i_engine is chrome.

This feature only is available in "Premium Plan" and above plans.

{p2i_adblock} false Block most of famous AD on the website by using https://easylist.to/easylist/easylist.txt filters. At the meanwhile, we will block the tracker as well.

Only p2i_engine=chrome support this feature. By default, p2i_engine is chrome.

This feature only is available in "Premium Plan" and above plans.

{p2i_proxy} null The address of a proxy server. We will use this proxy server to connect to the website and take screenshot. The proxy address should be formatted as address:port or user:password@address:port if authentication is needed.
For example: ip:port, http://ip:port, https://ip:port, socks5://ip:port, socks5://user:pass@ip:port

If the proxy server is slow, it will slow down the speed of taking screenshot observably.
Only p2i_engine=chrome support this feature. By default, p2i_engine is chrome.

This feature only is available in "xLarge Plan" and above plans.

{p2i_norobot} false Pass passes all public bot tests on 2020/06. Since it is a cat & mouse game, it may fail in the future. You can set p2i_norobot=1 if you want to bypass the robot checking.
Only p2i_engine=chrome support this feature. By default, p2i_engine is chrome.

This feature only is available in "xLarge Plan" and above plans.

Possible Return Values

All of the return format is Json format which supported by most of the programming languages.

If server is processing your request, you will receive:

{
"status":"processing",
"estimated_need_time":"15"
}

If server has finished your request, you will receive:
PS: image_url is JSON encoded.

{
"status":"finished",
"image_url":"http://api.page2images.com/images/00/00/10923423.jpg",
"duration":"11",
"left_calls":"923023"
}

Then you can download and do whatever you think is right on the images. We will keep this image for you for 24 hours. After that, due to the disk limitation, we will remove that image. Of cause, if you want to generate it again, we will capture it again.

If server encounter any problem, we will return:

{
"status":"error",
"errno":"403"
"msg": "detail information here"
}

Possible error messages are following:

Errno:403 Msg: The API Key does not exist.

Errno:403 Msg: Account does not have enough credits.

Errno:403 Msg: Account has expired.

Errno:403 Msg: You are using direct link key in Rest API.

Errno:404 Msg: We cannot access target URL.

Errno:500 Msg: Time out.

Sample Codes
Download Java sample source code for website screenshot
Download PHP sample source code for website screenshot
Download Python sample source code for website screenshot
Download PHP sample source code for convert HTML to image
Use Code Generator to Build the Code

Using our Code Generator, you can quickly generate the source code for IMG Tags. Use page2images code generator for website screenshot.

Free Engineering Service

Premium and XLarge rate plan users get free help with writing and testing code. Please contact us if you need help.

version:1.7