ApifyClient

new ApifyClient(optionsopt)

Parameters:

options
(
Object
)
<optional>
-
Global options for ApifyClient. You can globally configure here any method option from any namespace. For example
if you are working with just one crawler then you can preset it's crawlerId here instead of passing it to each
crawler's method.

userId
(
String
)
<optional>
-
Your user ID at apify.com

token
(
String
)
<optional>
-
Your API token at apify.com

expBackOffMillis
(
Number
)
<optional>
-
Wait time in milliseconds before repeating request to Apify API in a case of server
or rate limit error
Defaults to 500.

expBackOffMaxRepeats
(
Number
)
<optional>
-
Maximum number of repeats in a case of error
Defaults to 8.

tag
(
String
)
<optional>
-
Tag that is applied to the build on success. It enables callers of acts to specify which version of act to run.
betaPackages
useCache
tag

waitForFinish
(
Number
)
<optional>
-
Number of seconds to wait for act to finish. Maximum value is 120s.
If act doesn't finish in time then act run in RUNNING state is returned.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
ActBuild
)

createAct(options, callbackopt) → {Act}

Creates a new act.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

act
(
Object
)

callback
(
function
)
<optional>
-
Callback function

Returns:

(
Act
)

createActVersion(options) → {ActVersion}

Creates an act version.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

actId
(
String
)
-
Unique act ID

actVersion
(
Object
)
-
Act version

Returns:

(
ActVersion
)

deleteAct(options, callbackopt)

Deletes act.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

actId
(
String
)
-
Unique act ID

callback
(
function
)
<optional>
-
Callback function

deleteActVersion(options)

Deletes an act version.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

actId
(
String
)
-
Unique act ID

versionNumber
(
String
)
-
Version number of act version

Returns:

getAct(options, callbackopt) → {Act}

Gets act object.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

actId
(
String
)
-
Unique act ID

callback
(
function
)
<optional>
-
Callback function

Returns:

(
Act
)

getActVersion(options) → {ActVersion}

Gets an act version.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

actId
(
String
)
-
Unique act ID

versionNumber
(
String
)
-
Version number of act version

Returns:

(
ActVersion
)

getBuild(options, callbackopt) → {ActBuild}

Gets act build.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

actId
(
String
)
-
Unique act ID

buildId
(
String
)
-
Unique build ID

waitForFinish
(
Number
)
<optional>
-
Number of seconds to wait for act to finish. Maximum value is 120s.
If act doesn't finish in time then act run in RUNNING state is returned.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
ActBuild
)

getRun(options, callbackopt) → {ActRun}

Gets act run.

Parameters:

options
(
Object
)

actId
(
String
)
-
Unique act ID

runId
(
String
)
-
Unique run ID

token
(
String
)
<optional>
-
Your API token at apify.com

waitForFinish
(
Number
)
<optional>
-
Number of seconds to wait for act to finish. Maximum value is 120s.
If act doesn't finish in time then act run in RUNNING state is returned.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
ActRun
)

listActs(options, callbackopt) → {PaginationList}

By default, the objects are sorted by the createdAt field in ascending order,
therefore you can use pagination to incrementally fetch all acts while new ones are still being created.
To sort them in descending order, use desc: true parameter.
The endpoint supports pagination using limit and offset parameters and it will not return more than 1000 array elements.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

offset
(
Number
)
<optional>
-
Number of array elements that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of array elements to return.
Defaults to 1000.

desc
(
Boolean
)
<optional>
-
If true then the objects are sorted by the createdAt field in descending order.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
PaginationList
)

listActVersions(options) → {PaginationList}

Gets the list of versions of a specific act.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

actId
(
String
)
-
Unique act ID

Returns:

(
PaginationList
)

listBuilds(options, callbackopt) → {PaginationList}

Gets list of act builds.

By default, the objects are sorted by the startedAt field in ascending order,
therefore you can use pagination to incrementally fetch all builds while new ones are still being created.
To sort them in descending order, use desc: true parameter.

The endpoint supports pagination using limit and offset parameters and it will not return more than 1000 array elements.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

actId
(
String
)
-
Unique act ID

offset
(
Number
)
<optional>
-
Number of array elements that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of array elements to return.
Defaults to 1000.

desc
(
Boolean
)
<optional>
-
If true then the objects are sorted by the createdAt field in descending order.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
PaginationList
)

listRuns(options, callbackopt) → {PaginationList}

Gets list of act runs.

By default, the objects are sorted by the startedAt field in ascending order,
therefore you can use pagination to incrementally fetch all builds while new ones are still being created.
To sort them in descending order, use desc: true parameter.

The endpoint supports pagination using limit and offset parameters and it will not return more than 1000 array elements.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

actId
(
String
)
-
Unique act ID

offset
(
Number
)
<optional>
-
Number of array elements that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of array elements to return.
Defaults to 1000.

desc
(
Boolean
)
<optional>
-
If true then the objects are sorted by the createdAt field in descending order.

Parameters:

simplified
(
Number
)
<optional>
-
If 1 then the results will be returned in a simplified form without crawling metadata.

offset
(
Number
)
<optional>
-
Number of Request objects that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of Request objects to return.
Defaults to 100000.

desc
(
Number
)
<optional>
-
By default, results are returned in the same order as they were stored in database.
To reverse the order, set this parameter to 1.

attachment
(
Number
)
<optional>
-
If 1 then the response will define the Content-Disposition: attachment header, forcing a web
browser to download the file rather than to display it. By default this header is not present.

delimiter
(
String
)
<optional>
-
A delimiter character for CSV files, only used if format=csv. You might need to URL-encode
the character (e.g. use %09 for tab or %3B for semicolon).
Defaults to ','.

bom
(
Number
)
<optional>
-
All responses are encoded in UTF-8 encoding. By default, the csv files are prefixed with the UTF-8 Byte
Order Mark (BOM), while json, jsonl, xml, html and rss files are not. If you want to override this default
behavior, specify bom=1 query parameter to include the BOM or bom=0 to skip it.

xmlRow
(
String
)
<optional>
-
Overrides default element name that wraps each page or page function result object in xml output.
By default the element name is page or result based on value of simplified parameter.

hideUrl
(
Number
)
<optional>
-
If set to 1 then url field will not be added to each page function result object.
By default each page function result object contains url field.

skipFailedPages
(
Number
)
<optional>
-
If set to 1 then pages with non-empty errorInfo property are skipped from
the output and the errorInfo property is hidden.
Note that the skipped pages are still counted in the pagination.

skipHeaderRow
(
Number
)
<optional>
-
If set to 1 then header row in csv format is skipped.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
PaginationList
)

getLastExecution(options, callbackopt) → {Execution}

Gets information about the last execution of a specific crawler.

Optionally, you can use status parameter to only get the last execution with a specific status.

Parameters:

options
(
Object
)

userId
(
String
)
-
Your user ID at apify.com

token
(
String
)
-
Your API token at apify.com

crawlerId
(
String
)
-
Crawler ID or crawler custom ID

status
(
String
)
<optional>
-
Filter for the execution status.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
Execution
)

getLastExecutionResults(options, callbackopt) → {PaginationList}

Gets results of a last execution.

Parameters:

options
(
Object
)

userId
(
String
)
-
Your user ID at apify.com

token
(
String
)
-
Your API token at apify.com

crawlerId
(
String
)
-
Crawler ID or crawler custom ID

status
(
String
)
-
Filter for the execution status. This field is mandatory, it must have on of the following values:
RUNNING, SUCCEEDED, STOPPED, TIMEOUT or FAILED.

simplified
(
Number
)
<optional>
-
If 1 then the results will be returned in a simplified form without crawling metadata.

offset
(
Number
)
<optional>
-
Number of Request objects that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of Request objects to return.
Defaults to 100000.

desc
(
Number
)
<optional>
-
By default, results are returned in the same order as they were stored in database. To reverse
the order, set this parameter to 1.

attachment
(
Number
)
<optional>
-
If 1 then the response will define the Content-Disposition: attachment header, forcing a web
browser to download the file rather than to display it. By default this header is not present.

delimiter
(
String
)
<optional>
-
A delimiter character for CSV files, only used if format=csv. You might need to URL-encode
the character (e.g. use %09 for tab or %3B for semicolon).
Defaults to ','.

bom
(
Number
)
<optional>
-
All responses are encoded in UTF-8 encoding. By default, the csv files are prefixed with the UTF-8 Byte
Order Mark (BOM), while json, jsonl, xml, html and rss files are not. If you want to override this default
behavior, specify bom=1 query parameter to include the BOM or bom=0 to skip it.

xmlRow
(
String
)
<optional>
-
Overrides default element name that wraps each page or page function result object in xml output.
By default the element name is page or result based on value of simplified parameter.

hideUrl
(
Number
)
<optional>
-
If set to 1 then url field will not be added to each page function result object.
By default each page function result object contains url field.

skipFailedPages
(
Number
)
<optional>
-
If set to 1 then pages with non-empty errorInfo property are skipped from
the output and the errorInfo property is hidden.
Note that the skipped pages are still counted in the pagination.

skipHeaderRow
(
Number
)
<optional>
-
If set to 1 then header row in csv format is skipped.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
PaginationList
)

getListOfExecutions(options, callbackopt) → {PaginationList}

Gets a list of executions of a specific crawler.

Optionally, you can use status parameter to filter the list to only contain executions with a specific
status (for example, status 'RUNNING' will only return executions that are still running).

Parameters:

options
(
Object
)

userId
(
String
)
-
Your user ID at apify.com

token
(
String
)
-
Your API token at apify.com

crawlerId
(
String
)
-
Crawler ID or crawler custom ID

status
(
String
)
<optional>
-
Filter for the execution status.

offset
(
Number
)
<optional>
-
Number of array elements that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of array elements to return.
Defaults to 1000.

desc
(
Number
)
<optional>
-
If 1 then the executions are sorted by the startedAt field in descending order.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
PaginationList
)

listCrawlers(options, callbackopt) → {PaginationList}

By default, the objects are sorted by the createdAt field in ascending order,
therefore you can use pagination to incrementally fetch all crawlers while new ones are still being created.
To sort them in descending order, use desc: 1 parameter.

Parameters:

options
(
Object
)

userId
(
String
)
-
Your user ID at apify.com

token
(
String
)
-
Your API token at apify.com

offset
(
Number
)
<optional>
-
Number of array elements that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of array elements to return.
Defaults to 1000.

desc
(
Number
)
<optional>
-
If 1 then the crawlers are sorted by the createdAt field in descending order.

Parameters:

offset
(
Number
)
<optional>
-
Number of array elements that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of array elements to return.
Defaults to 100000.

desc
(
Number
)
<optional>
-
If true then the objects are sorted by createdAt in descending order.
Otherwise they are sorted in ascending order.

fields
(
Array
)
<optional>
-
An array of field names that will be included in the result. If omitted, all fields are included in the results.

unwind
(
String
)
<optional>
-
Specifies a name of the field in the result objects that will be used to unwind the resulting objects.
By default, the results are returned as they are.

disableBodyParser
(
Boolean
)
<optional>
-
If true then response from API will not be parsed

attachment
(
Number
)
<optional>
-
If true then the response will define the Content-Disposition: attachment HTTP header, forcing a web
browser to download the file rather than to display it. By default, this header is not present.

delimiter
(
String
)
<optional>
-
A delimiter character for CSV files, only used if format is csv.
You might need to URL-encode the character (e.g. use %09 for tab or %3B for semicolon).
Defaults to ','.

bom
(
Number
)
<optional>
-
All responses are encoded in UTF-8 encoding. By default, the CSV files are prefixed with the UTF-8 Byte
Order Mark (BOM), while JSON, JSONL, XML, HTML and RSS files are not. If you want to override this default
behavior, set bom option to true to include the BOM, or set bom to false to skip it.

xmlRoot
(
String
)
<optional>
-
Overrides the default root element name of the XML output. By default, the root element is results.

xmlRow
(
String
)
<optional>
-
Overrides the default element name that wraps each page or page function result object in XML output.
By default, the element name is page or result, depending on the value of the simplified option.

skipHeaderRow
(
Boolean
)
<optional>
-
If set to 1 then header row in csv format is skipped.

token
(
String
)
<optional>
-
Your API token at apify.com

callback
(
function
)
<optional>
-
Callback function

Returns:

(
PaginationList
)

getOrCreateDataset(options, callbackopt) → {Dataset}

Creates dataset of given name and returns it's object. If data with given name already exists then returns it's object.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

datasetName
(
String
)
-
Custom unique name to easily identify the dataset in the future.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
Dataset
)

listDatasets(options, callbackopt) → {PaginationList}

Returns a list of datasets owned by a user.

By default, the objects are sorted by the createdAt field in ascending order,
therefore you can use pagination to incrementally fetch all datasets while new ones are still being created.
To sort them in descending order, use desc: true option.
The endpoint supports pagination using limit and offset parameters and it will not return more than 1000 array elements.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

offset
(
Number
)
<optional>
-
Number of array elements that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of array elements to return.
Defaults to 1000.

desc
(
Boolean
)
<optional>
-
If true then the objects are sorted by the startedAt field in descending order.

unnamed
(
Boolean
)
<optional>
-
If true then also unnamed stores will be returned. By default only named stores are returned.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
PaginationList
)

putItems(options, callbackopt) → {*}

Saves the object or an array of objects into dataset.

Parameters:

options
(
Object
)

datasetId
(
String
)
-
Unique dataset ID

data
(
Object
|
Array
|
String
)
-
Object, Array of objects or a String. String must be a valid JSON.
Arrays and Objects must be JSON.stringifiable.

Parameters:

disableRedirect
(
Boolean
)
<optional>
-
API by default redirects user to signed record url for faster download.
If disableRedirect=1 is set then API returns the record value directly.

token
(
String
)
<optional>
-
Your API token at apify.com

callback
(
function
)
<optional>
-
Callback function

Returns:

(
KeyValueStoreRecord
)

getStore(options, callbackopt) → {KeyValueStore}

Gets key-value store.

Parameters:

options
(
Object
)

storeId
(
String
)
-
Unique store ID

token
(
String
)
<optional>
-
Your API token at apify.com

callback
(
function
)
<optional>
-
Callback function

Returns:

(
KeyValueStore
)

listKeys(options, callbackopt) → {PaginationList}

Returns an array containing objects representing keys in given store.

You can paginated using exclusiveStartKey and limit parameters.

Parameters:

options
(
Object
)

storeId
(
String
)
-
Unique store ID

exclusiveStartKey
(
String
)
<optional>
-
All keys up to this one (including) are skipped from the result.

limit
(
Number
)
<optional>
-
Number of keys to be returned. Maximum value is 1000

token
(
String
)
<optional>
-
Your API token at apify.com

callback
(
function
)
<optional>
-
Callback function

Returns:

(
PaginationList
)

listStores(options, callbackopt) → {PaginationList}

Gets list of key-value stores.

By default, the objects are sorted by the createdAt field in ascending order,
therefore you can use pagination to incrementally fetch all stores while new ones are still being created.
To sort them in descending order, use desc: true parameter.
The endpoint supports pagination using limit and offset parameters and it will not return more than 1000 array elements.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

offset
(
Number
)
<optional>
-
Number of array elements that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of array elements to return.
Defaults to 1000.

desc
(
Boolean
)
<optional>
-
If true then the objects are sorted by the startedAt field in descending order.

unnamed
(
Boolean
)
<optional>
-
If true then also unnamed stores will be returned. By default only named stores are returned.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
PaginationList
)

putRecord(options, callbackopt) → {*}

Saves the record into key-value store.

Parameters:

options
(
Object
)

storeId
(
String
)
-
Unique store ID

key
(
String
)
-
Key of the record

contentType
(
String
)
-
Content type of body

body
(
string
|
Buffer
)
-
Body in string or Buffer

token
(
String
)
<optional>
-
Your API token at apify.com

callback
(
function
)
<optional>
-
Callback function

Returns:

(
*
)

ApifyClient.logs

Logs

Methods (1)

getLog(options, callbackopt) → {Promise.<string>|null}

Parameters:

options
(
Object
)

logId
(
String
)
-
ID of the log which is either ID of the act build or ID of the act run.

Returns:

getOrCreateQueue(options, callbackopt) → {RequestQueue}

Creates request queue of given name and returns it's object. If queue with given name already exists then returns it's object.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

queueName
(
String
)
-
Custom unique name to easily identify the queue in the future.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
RequestQueue
)

getQueue(options, callbackopt) → {RequestQueue}

Gets request queue.

Parameters:

options
(
Object
)

queueId
(
String
)
-
Unique queue ID

token
(
String
)
<optional>
-
Your API token at apify.com

callback
(
function
)
<optional>
-
Callback function

Returns:

(
RequestQueue
)

getRequest(options, callbackopt) → {Request}

Gets request from the queue.

Parameters:

options
(
Object
)

queueId
(
String
)
-
Unique queue ID

requestId
(
String
)
-
Unique request ID

token
(
String
)
<optional>
-
Your API token at apify.com

callback
(
function
)
<optional>
-
Callback function

Returns:

(
Request
)

listQueues(options, callbackopt) → {PaginationList}

Gets list of request queues.

By default, the objects are sorted by the createdAt field in ascending order,
therefore you can use pagination to incrementally fetch all queues while new ones are still being created.
To sort them in descending order, use desc: true parameter.
The endpoint supports pagination using limit and offset parameters and it will not return more than 1000 array elements.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

offset
(
Number
)
<optional>
-
Number of array elements that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of array elements to return.
Defaults to 1000.

desc
(
Boolean
)
<optional>
-
If true then the objects are sorted by the startedAt field in descending order.

unnamed
(
Boolean
)
<optional>
-
If true then also unnamed stores will be returned. By default only named stores are returned.

getTask(options, callbackopt) → {Task}

Parameters:

Returns:

(
Task
)

listRuns(options, callbackopt) → {PaginationList}

Gets list of task runs.

By default, the objects are sorted by the startedAt field in ascending order,
therefore you can use pagination to incrementally fetch all builds while new ones are still being created.
To sort them in descending order, use desc: true parameter.

The endpoint supports pagination using limit and offset parameters and it will not return more than 1000 array elements.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

taskId
(
String
)
-
Unique task ID

offset
(
Number
)
<optional>
-
Number of array elements that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of array elements to return.
Defaults to 1000.

desc
(
Boolean
)
<optional>
-
If true then the objects are sorted by the createdAt field in descending order.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
PaginationList
)

listTasks(options, callbackopt) → {PaginationList}

By default, the objects are sorted by the createdAt field in ascending order,
therefore you can use pagination to incrementally fetch all tasks while new ones are still being created.
To sort them in descending order, use desc: true parameter.
The endpoint supports pagination using limit and offset parameters and it will not return more than 1000 array elements.

Parameters:

options
(
Object
)

token
(
String
)
-
Your API token at apify.com

offset
(
Number
)
<optional>
-
Number of array elements that should be skipped at the start.
Defaults to 0.

limit
(
Number
)
<optional>
-
Maximum number of array elements to return.
Defaults to 1000.

desc
(
Boolean
)
<optional>
-
If true then the objects are sorted by the createdAt field in descending order.

callback
(
function
)
<optional>
-
Callback function

Returns:

(
PaginationList
)

runTask(options, callbackopt) → {ActRun}

Runs the given task.

Parameters:

options
(
Object
)

taskId
(
String
)
-
Unique task ID

token
(
String
)
<optional>
-
Your API token at apify.com

waitForFinish
(
Number
)
<optional>
-
Number of seconds to wait for task to finish. Maximum value is 120s.
If task doesn't finish in time then task run in RUNNING state is returned.