API Documentation
  • Public
  • Public/Protected
  • All
Menu HTTP Endpoint API Client Library Documentation

This documentation is for the HTTP Endpoint. For GET and POST requests.

Using Curl, C#, PHP, Python, or Node.js?

For API Libraries and Examples in these or other languages, refer to the Docs Index Page

Examples! (Quick Start)

These examples use GET requests because they are the simplest way of showing examples and getting started, but it is strongly suggested you use the POST endpoint for "real" usage.

Basic Examples:

Advanced Examples:

Other Examples: See the Docs Index Page Usage FAQ for other examples (such as Page Automation / Button Clicking)


To use this API, you need to submit a GET or POST request to the API endpoint:


GET requests are the simplest way of showing examples and getting started, but it is strongly suggested you use the POST endpoint for "real" usage.

  • Url (uriComponent encoded requests)
    • http(s)://[YOUR-KEY]/?request=[REQUEST-JSON]
    • The entirety of your [REQUEST-JSON] should be encoded via encodeURIComponent(), do not encode the parts individually.
  • Url (base64 encoded requests)
    • http(s)://[YOUR-KEY]/?requestBase64=[REQUEST-JSON]
    • The entirety of your [REQUEST-JSON] should be Base64 Encoded., do not encode the parts individually, and do not urlEncode before you Base64 Encode.


  • Url
    • http(s)://[YOUR-KEY]/
  • Post Body
    • You should not Base64 Encode, nor UrlEncode your Post Body, or any of it's parts.
  • Content Type
    • application/json

Input Parameters


Your key used for creditBalance/billing. For the Stage2 Preview, this can be anything you want. Later you can obtain this by signing up.


The details of your request as a JSON object. This JSON can take one of the following three forms, each of which are described on the io-datatypes doc page:

  • A single PageRequest object (the simplest approach)
    • Example: {url:"",renderType:"jpg",outputAsJson:true}
  • Array of PageRequest objects
    • Example: [{url:""},{url:"",renderType:"jpg",outputAsJson:true}]
  • A UserRequest object (Most complex: required if you want to use Proxy Servers).
    • Example: {proxy:false,pages:[{url:""},{url:"",renderType:"jpg",outputAsJson:true}]}

PageRequest Default Values

While the url is required, everything else is optional. Click here to view the default values if you leave the various parameters blank

CORS/JSONP (Browser API Support)

You can use CORS (prefered) or JSONP to integrate api calls from PhantomJs Cloud directly into your webpage.

  • CORS: All endpoint are CORS enabled by default.
  • JSONP: To obtain results in JSONP format, add the ?callback=CALLBACK_FUNCTION_NAMEquerystring to your request (for either GET or POST requests). You MUST set outputAsJson:true for JSONP to work. See the Advanced Examples section for a demo.

Additional Documentation

Please refer to the main Docs Index Page for Basic Troubleshooting, Testing and Performance Optimization, Usage FAQ, and language-specific samples.


External modules

External modules





This property defines the rectangular area of the web page to be rasterized when using the requestType of png or jpeg. If no clipping rectangle is set, the entire web page is captured.


height: number


left: number


top: number


width: number



Various methods in the phantom object, as well as in WebPage instances, utilize phantom.cookies objects. These are best created via object literals.


domain: string


expires: number

unix epoch timestamp (in ms) Javascript Example: (new Date()).getTime() + (1000 * 60 * 60) // <-- expires in 1 hour


httponly: boolean


name: string


path: string


secure: boolean


value: string



information about the frames of the page


childCount: number

number of children contained by this frame


childFrames: IPageFrame[]

the children of this page (a hiearchy of frames)


content: string

the html content of the frame


name: string

the name of the frame. use this when requesting the frame to be rendered


url: string

the url of the frame



The parameters for requesting and rendering a page. When you submit an array of IPageRequests, they are loaded in-orrder, and only the last one is rendered. All variables except 'url' are optional.


content: string

if specified, will be used as the content of the page you are loading (no network request will be made for the url). However, the url property is still required, as that will be used as the page's "pretend" url example: content:"<h1>Hello, World!</h1>",url:"about:blank"


outputAsJson: boolean

TRUE to return the page conents and metadata as a JSON object. see IUserResponse if FALSE, we return the rendered content in it's native form.


renderSettings: IRenderSettings

settings related to rendering of the last page of your request. See the IRenderSettings documentation (below) for details


renderType: string

"html": returns the html text, "jpeg"|"jpg" : The default. renders page as jpeg. transparency not supported. (use png for transparency), "png": renders page as png, "pdf": renders page as a pdf, "script": returns the contents of window['_pjscMeta'].scriptOutput. see the scripts parameter for more details, "plainText": return the text without html tags (page plain text),


requestSettings: IRequestSettings

settings related to requesting internet resources (your page and resources referenced by your page)


scripts: IScripts

Execute your own custom JavaScript inside the page being loaded. see IScripts docs for more details.


suppressJson: string[]

add the nodes from your pageResponse that you do not wish to transmit. This reduces the size of your data, thus reducing cost and transmission time. if you need the data in these nodes, simply remove it from this array.


url: string

required. the target page you wish to load


urlSettings: IUrlSettings

adjustable parameters for when making network requests to the url specified



Information about the page transaction (request and it's response).


cookies: ICookie[]

cookies set at the moment the page transaction completed.


events: Array<object>

events that occured during requesting and loading of the page and it's content


frameData: IPageFrame

the Frames contained in the page. The first is always the main page itself, even if no other frames are present.


headers: object[]

headers for the primary resource (the url requested). for headers of other resources, inspect the (key='resourceReceived')

Type declaration

  • name: string
  • value: string


metrics: object

information about the processing of your request

Type declaration

  • elapsedMs: number
  • endTime: string
  • pageStatus: string
  • startTime: string


pageRequest: IPageRequest

the request you sent, including defaults for any parameters you did not include


scriptOutput: any


statusCode: number

the status code for the page, a shortcut to metrics.targetUrlReceived.value.status



options for specifying headers or footers in a pdf render.


firstPage: string

if specified, this is used for the first page (instead of the repeating)


height: string

required. Supported dimension units are: 'mm', 'cm', 'in', 'px'. No unit means 'px'.


lastPage: string

if specified, this is used for the last page (instead of the repeating)


onePage: string

if specified, this is used for single page pdfs (instead of the repeating)


repeating: string

specify a header used for each page. use wildcards for pageNum,numPages as shown in this example: repeating:<h1><span style='float:right'>%pageNum%/%numPages%</span></h1>



options specific to rendering pdfs. IMPORTANT NOTE: we strongly recommend using px as your units of measurement.


border: string

Border is optional and defaults to 0. A non-uniform border can be specified in the form {left: '2cm', top: '2cm', right: '2cm', bottom: '3cm'} Use of px is strongly recommended.


dpi: number

set the DPI for pdf generation. defaults to 150, which causes each page to be 2x as large (use "fit to paper" when printing) If you want exact, proper page dimensions, set this to 72.


settings for footers of the pdf


format: string

Supported formats are: 'A3', 'A4', 'A5', 'Legal', 'Letter', 'Tabloid'. .


settings for headers of the pdf


height: string

height and width are optional if format is specified. Use of px is strongly recommended. Supported dimension units are: 'mm', 'cm', 'in', 'px'. No unit means 'px'.


orientation: string

optional. ('portrait', 'landscape') and defaults to 'portrait'


width: string

height and width are optional if format is specified. Use of px is strongly recommended. Supported dimension units are: 'mm', 'cm', 'in', 'px'. No unit means 'px'.



optional png quality options passed to PngQuant. you must set pngOptions.optimize=true to enable these, otherwise the original non-modified png is returned.


colors: number

2 to 256. default 256.


noDither: boolean

default false. true to disable dithering


optimize: boolean

default false, which is to return the original png. if you pass true, we will optimize the png using PngQuant. smaller file size but takes longer to process


qualityMax: number

1 to 100. default 80. Instructs pngquant to use the least amount of colors required to meet or exceed the max quality.


qualityMin: number

default 0. If conversion results in quality below the min quality the image won't be compressed


speed: number

default 8. (very fast). value can rage between 1 (slow) and 11 (fast and rough)




auth: string

authentication information for the proxy. ex: username:password


host: string

the address and port of the proxy server to use. ex: If your proxy requires a IP to whitelist, use for your requests.


type: string

type of the proxy server. default is http available types are http, socks5, and none



allows specifying a proxy for your userRequest (all the pageRequests it contains) To use the built-in proxy servers, you must set the geolocation parameter. Alternatively, you may use your own custom proxy server by setting the custom parameter.


allows you to use a custom proxy server. if you set this, the built-in proxy will not be used. default=NULL


geolocation: string

specify the geographic region of the builtin proxy server you use. defaults to any. possible values are any, us (usa), de (germany), gb (great britan), ca (canada), sg (singapore) IMPORTANT: Not yet implemented. So for now, all values are treated as any


instanceId: number

specify what builtin proxy server you use. by default, the auto-proxy system will randomly pick from an available proxy server. If you want to specify a specific (fixed) proxy server, set this instanceId to a number, then all requests will direct to the same builtin server.. If you want to use the proxy server in a round-robin style (recommended!) each request should increment this instanceId by one.



when a page is rendered, use these settings.


clipRectangle: IClipRectangleOptions

This property defines the rectangular area of the web page to be rasterized when using the requestType of png or jpeg. If no clipping rectangle is set, the entire web page is captured. Beware: if you capture too large an image it can cause your request to fail (out of memory). you can choose any dimensions you wish as long as you do not exceed 32M pixels


passThroughHeaders: boolean

default false. If true, we will pass through all headers received from the target URL, with the exception of "Content-Type" (unless the renderType=html)


pdfOptions: IPdfOptions

pdf specific settings. Example:

border: "0",
footer: {
firstPage: "", height: "1cm", lastPage: "", onePage: "", repeating: "<h1><span style='float:right'>%pageNum%/%numPages%</span></h1>"
format: "letter",
header: {
firstPage: "", height: "0cm", lastPage: "", onePage: "", repeating: ""
height: "11in",
orientation: "portrait",
width: "8.5in",     }


pngOptions: IPngOptions

optional png quality options passed to PngQuant. you must set pngOptions.optimize=true to enable these, otherwise the original non-modified png is returned.


quality: number

jpeg quality. 0 to 100. default 70. ignored for png, use pngOptions to set png quality.


renderIFrame: string

specify an IFrame to render instead of the full page. must be the frame's name.


viewport: object

size of the browser in pixels

Type declaration

  • height: number

    height is not used when taking screenshots (png/pdf). The image will be as tall as required to fit the content. To set your screenshot's dimensions, use the pageRequest.clipRectangle property.

  • width: number


zoomFactor: number

This property specifies the scaling factor for the screenshot (requestType png/pdf) choices. The default is 1, i.e. 100% zoom.



settings related to requesting internet resources (your page and resources referenced by your page)


authentication: object

username/password for simple HTTP authentication

Type declaration

  • password: string
  • userName: string


clearCache: boolean

if true, will clear the browser memory cache before processing the request. Good for expiring data, and very important if blacklisting resources (see resourceModifier parameter). Default is false.


clearCookies: boolean

if true, will clear cookies before processing the request. Default is false. IMPORTANT NOTE: to protect your privacy, we always clear cookies after completing your transaction. This option is only useful if making multiple requests in one transaction (IE: multiple pageRequests in a userRequest API call)


cookies: ICookie[]

Set Cookies for any domain, prior to loading this pageRequest. If a cookie already exists with the same domain+path+name combination, it will be replaced. See ICookie for documentation on the cookie parameters.


customHeaders: object

specify additional request headers here. They will be sent to the server for every request issued (the page and resources). Unicode is not supported (ASCII only) example: customHeaders:{"myHeader":"myValue","yourHeader":"someValue"} if you want to set headers for just the target page (and not every sub-request) use the pageRequest.urlSettings.headers parameter.

Type declaration

  • [key: string]: string


deleteCookies: string[]

delete any cookie with a matching "name" property before processing the request.


disableJavascript: boolean

set to true to disable all Javascript from being processed on your page.


ignoreImages: boolean

set to true to skip loading of inlined images. If you are not outputing a screenshot, you can usually set this to true, which will decrease load times.


maxWait: number

the maximum amount of time (timeout) you wish to wait for the page to finish loading. When rendering a page, we will give you whatever is ready at this time (page may be incompletely loaded). Can be increased up to 5 minutes, but that only should be used as a last resort, as it is a relatively expensive page render.


resourceModifier: IResourceModifier[]

array of regex + adjustment parametes for modifying or rejecting resources being loaded by the webpage. Example: "resourceModifier": [{regex:".*css.*",isBlacklisted:true}{"regex": "*","setHeader": {"hello": "world","Accept-encoding": "tacos"}}] IMPORTANT NOTE: If you use this to blacklist resources, it is strongly recommended you also set the clearCache parameter. This is because cached resources are not requested, and thus will not be able to be blacklisted.


resourceTimeout: number

maximum amount of time to wait for each external resource to load. we kill the request if it exceeds this amount.


resourceWait: number

maximum amount of time to wait for each external resources to load. (.js, .png, etc) if the time exceeds this, we don't cancel the resource request, but we don't delay rendering the page if everything else is done.


stopOnError: boolean

if true, will stop page load upon the first error detected, and move to next phase (render or next page)


userAgent: string

default useragent is "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) Safari/534.34 PhantomJS/2.0.0 ("


waitInterval: number

Milliseconds to delay rendering after the last resource is finished loading (default is 1000ms). This is useful in case there are any AJAX requests or animations that need to finish up. If additional network requests are made while we are waiting, the waitInterval will restart once finished again. This can safely be set to 0 if you know there are no AJAX or animations you need to wait for (decreasing your billed costs)


webSecurityEnabled: boolean

set to true to enable web security. default is false


xssAuditingEnabled: boolean

set to true to prohibit cross-site scripting attempts (XSS)



regex + adjustment parametes for modifying or rejecting resources being loaded by the webpage. Example: {regex:".*css.*",isBlacklisted:true}


changeCaptureRegex: string

special pattern matching regex. capture groups can replace parts of the changeUrl that use the special marker tokens $$0, $$1, etc on to $$9 . for example: if resourceUrl="" changeCaptureRegex="^.*?/(.*)$" would create a match group for everything after the last / character and changeUrl="$$1" would then get evaluated to ""


changeUrl: string

changes the current URL of the network request. This is an excellent and only way to provide alternative implementation of a remote resource. you can even use a dataURI so that you can set the contents directly, Example: data:,Hello%2C%20World! additionally, you can use special marker tokens to replace parts of the changeUrl with the original resource url. the special marker tokens are $$port $$protocol```` $$host```$$path. For example changeUrl="$$protocol://$$path" also, you can use the changeCaptureRegex parameter to provide custom marker tokens.


isBlacklisted: boolean

if true, blacklists the request unless a later matching resourceAdjustor changes it back to false (we process in a FIFO fashion) by default, we don't blacklist anything. You should keep it this way when rendering jpeg (where the visuals matter), if processing text/data, blacklisting .css files ['..css.'] will work fine. check the response.metrics for other resources you could blacklist (example: facebook, google analytics, ad networks)


regex: string

pattern used to match a resource's url examples: it really depends what the site is and what you are wanting to block, but for example to block anything with the text "facebook" or "linkedin" in the url:

javascript requestModifiers:[{regex:".*facebook.*",isBlacklisted:true},{regex:".*linkedin.*",isBlacklisted:true}]

It's especially useful if you just need the text, as you can block all css files from loading, such as: ".*\.css.*"

Don't use this to block images. instead, images are blocked by using the requestSettings.ignoreImages:true property


setHeader: object

optional key/value pairs for adjusting the headers of this resource's request. example: {"Accept-encoding":"gzip", "hello":"world"}

Type declaration

  • [key: string]: string



properties exposed to your custom scripts via window._pjscMeta


forceFinish: boolean

set to false by default. set to true to force rendering immediately. good for example, when you want to render as soon as domReady happens


manualWait: boolean

set to false by default. if true, will delay rendering until you set it back to false. good if you are waiting on an AJAX event.


optionsOverrides: object

allows you to override specific pageRequest options with values you compute in your script (based on the document at runtime)

Type declaration

  • Optional clipRectangle?: IClipRectangleOptions

    set the clipRectangle for image rendering. here is an example you can run in your domReady or loadFinished script: _pjscMeta.optionsOverrides.clipRectangle = document.querySelector("h1").getBoundingClientRect();


pageResponse: IPageResponse

Scripts can access (readonly) details about the page being loaded via window._pjscMeta.pageResponse See IPageResponse for more details.


scriptOutput: object

Your scripts can return data to you in the pageResponse.scriptOutput object. You can access this directly via windows._pjscMeta.scriptOutput or your script can simply return a value and it will be set as the scriptOutput (not available on external, url loaded scripts)

Type declaration


scriptsExecuted: number

how many custom scripts have been loaded so far



Execute your own custom JavaScript inside the page being loaded. INPUT You can pass in either the url to a script to load, or the text of the script itself. Example: scripts:{domReady:["//","return 'Hello, World!';"]} OUTPUT Your scripts can return data to you in the pageResponse.scriptOutput object. You can access this directly via windows._pjscMeta.scriptOutput or your script can simply return a value and it will be set as the scriptOutput (not available on external, url loaded scripts) Also, if you use the pageRequest.renderType="script" setting, your response will be the scriptOutput itself (in JSON format) which allows you to construct your own custom API. A very powerfull feature! *


domReady: string[]

triggers when the dom is ready for the current page. Please note that the page may still be loading.


loadFinished: string[]

triggers when we determine the page has been completed. If your page is being rendered, this occurs immediately before then. IMPORTANT NOTE: Generally you do NOT want to load external scripts (url based) here, as it will hold up rendering. Consider putting your external scripts in domReady



adjustable parameters for when making network requests to the url specified. used by PageRequest.


data: any

submitted in POST BODY of your request.


encoding: string

defaults to 'utf8'


headers: object

custom headers for the taret page. if you want to set headers for every sub-resource requested, use the pageRequest.requestSettings.customHeaders parameter instead.

Type declaration

  • [key: string]: string


operation: string

GET (default) or POST



The 'main' form of user request, allows specifying pages to load in order. Later will provide other 'global' options such as geolocation choices.


backend: string

optional, specify an alternate backend instead of the default phantomjs process. the default value if not specified is default. options are: default: the current stable backend. (phantomjs v2.1.1). beta: the latest backend we are testing (phantomjs v2.5b). You can also specify an exact backend: phantom 2.1.1 or phantom 2.5beta.


outputAsJson: boolean

setting this forces the value of the outputAsJson parameter, regardless of what the last page's value of outputAsJson was set to. default is undefined.


pages: IPageRequest[]

array of pages you want to load, in order. Only the last successfully loaded page will be rendered.


proxy: boolean | IProxyOptions

Use proxy servers for your request. default=false. set to true to enable our builtin proxy servers, or use the parameters found at IProxyOptions for more control/options, including the ability to specify your own custom proxy server. IMPORTANT: for now, to use the builtin proxy servers, you must use the api endpoints found at This is because our proxy provider requires Whitelisting us by Static IP addresses. This requirement will be removed after we exit Beta. Additionally, When you use proxy servers, be aware that requests will be slower, so consider increasing the pageRequest.resourceTimeout parameter like the Proxy Example does.



This is returned to you when "outputAsJson=true".


content: object

the rendered output of the last pageRequest

Type declaration

  • data: string

    data in either base64 or utf8 format

  • encoding: string

    utf8 or base64

  • Optional headers?: object[]

    headers of the target url, only set if pageRequest.renderSettings.passThroughHeaders===true

    • name: string
    • value: string
  • name: string

    filename you could use if saving the content to disk. this will be something like 'content.text', 'content.jpeg', 'content.pdf' thus this informs you of the content type

  • size: number

    the size of data, in bytes

  • statusCode: number
  • url: string

    the final url of the page after redirects


meta: object

metadata about the transaction

Type declaration

  • Optional backend?: object

    information about the system processing this transaction

    • id: string

      identifier of the system, for troubleshooting purposes

    • os: string
    • platform: string


    • platformVersion: any

      version of phantomjs. (major/minor/point)

    • requestsProcessed: number

      number of requests processed by this backend

  • Optional billing?: object

    how much this transaction costs. NOTE: the creditCost, prepaidCreditsRemaining, and dailySubscriptionCreditsRemaining are also returning in the HTTP Response Headers via the keys pjsc-credit-cost, pjsc-daily-subscription-credits-remaining, and pjsc-prepaid-credits-remaining

    • bytes: number
    • Optional creditCost?: number

      the total cost of this response

    • Optional dailySubscriptionCreditsRemaining?: number

      estimation of your remaining daily creditBalance. This is incrementally refilled hourly.

    • elapsedMs: number
    • Optional prepaidCreditsRemaining?: number
  • Optional outputAsJson?: boolean

    hint our pjsc-be-phantom writes so api endpoint knows if should send back only the content.


originalRequest: IUserRequest

the original request, without defaults applied. to see the request with defaults, see pageResponses.pageRequest


pageResponses: IPageResponse[]

a collection of load/processing information for each page you requested.


statusCode: number

the HTTP Status Code PhantomJsCloud returns to you