Apify API client for JavaScript 0.6.0

ApifyClient

new ApifyClient(optionsopt)

Basic usage of ApifyClient:

const ApifyClient = require('apify-client');

const apifyClient = new ApifyClient({
  userId: 'jklnDMNKLekk',
  token: 'SNjkeiuoeD443lpod68dk',
});

All API calls done through this client are made with exponential backoff. What this means, is that if the API call fails, this client will attempt the call again with a small delay. If it fails again, it will do another attempt after twice as long and so on, until one attempt succeeds or 8th attempt fails.

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 actor then you can preset it's actId here instead of passing it to each actor'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.
    • retryOnStatusCodes ( Array.<Number> ) <optional> - An array of status codes on which request gets retried. By default requests are retried only in a case of limit error (status code 429). Defaults to [429].

Methods (2)

getOptions() → {Object}

Returns options of ApifyClient instance.

Returns:
  • ( Object ) - See ApifyClient constructor options
  • setOptions(options)

    Overrides options of ApifyClient instance.

    Parameters:

    ApifyClient.acts

    Basic usage

    Every method can be used as either promise or with callback. If your Node version supports await/async then you can await promise result.

    const ApifyClient = require('apify-client');
    
    const apifyClient = new ApifyClient({
     userId: 'jklnDMNKLekk',
     token: 'SNjkeiuoeD443lpod68dk',
    });
    
    // Awaited promise
    try {
         const actors = await apifyClient.acts.listActs({});
         // Do something actors list ...
    } catch (err) {
         // Do something with error ...
    }
    
    // Promise
    apifyClient.acts.listActs({})
    .then((actsList) => {
         // Do something actsList ...
    })
    .catch((err) => {
         // Do something with error ...
    });
    
    // Callback
    apifyClient.acts.listActs({}, (err, actsList) => {
         // Do something with error or actsList ...
    });

    Methods (22)

    abortBuild(options, callbackopt) → {ActBuild}

    Abort act build.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • actId ( String ) - Unique act ID
      • buildId ( String ) - Unique build ID
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( ActBuild )
  • abortRun(options, callbackopt) → {ActRun}

    Abort act run.

    Parameters:
    • options ( Object )
      • actId ( String ) - Unique act ID
      • runId ( String ) - Unique run ID
      • token ( String ) <optional> - Your API token at apify.com
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( ActRun )
  • buildAct(options, callbackopt) → {ActBuild}

    Builds given act and returns object of that build.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • actId ( String ) - Unique act ID
      • version ( String ) - Version of the act to build.
      • betaPackages ( Boolean ) <optional> - If true, the Docker container will be rebuild using layer cache. This is to enable quick rebuild during development.
      • useCache ( Boolean ) <optional> - If true, Docker build uses beta versions of 'apify-client' and 'apify' NPM packages, to test new features.
      • 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.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( PaginationList )
  • listWebhooks(options, callbackopt) → {PaginationList}

    Gets list of webhooks for given actor.

    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 )
  • listWebhooks(options, callbackopt) → {PaginationList}

    Gets list of webhooks for given actor task.

    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 )
  • metamorphRun(options, callbackopt) → {ActRun}

    Transforms the actor run to an actor run of a given actor.

    Parameters:
    • options ( Object )
      • actId ( String ) - Unique act ID
      • token ( String ) - Your API token at apify.com
      • runId ( String ) - ID a an actor run to metamorph.
      • targetActorId ( String ) - ID of an actor to which run should metamorph.
      • body ( String | Buffer ) <optional> - Act input, passed as HTTP POST payload
      • contentType ( String ) <optional> - Content type of act input e.g 'application/json'
      • build ( String ) <optional> - Tag or number of the build to run (e.g. latest or 1.2.34).
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( ActRun )
  • resurrectRun(options, callbackopt) → {ActRun}

    Resurrects finished (even failed) actor run. Container gets restarted with original storages.

    Parameters:
    • options ( Object )
      • actId ( String ) - Unique act ID
      • runId ( String ) - Unique run ID
      • token ( String ) <optional> - Your API token at apify.com
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( ActRun )
  • runAct(options, callbackopt) → {ActRun}

    Runs the latest build of given act.

    Parameters:
    • options ( Object )
      • actId ( String ) - Unique act ID
      • token ( String ) <optional> - Your API token at apify.com
      • body ( String | Buffer ) <optional> - Act input, passed as HTTP POST payload
      • contentType ( String ) <optional> - Content type of act input e.g 'application/json'
      • 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.
      • timeout ( Number ) <optional> - Timeout for the act run in seconds. Zero value means there is no timeout.
      • memory ( Number ) <optional> - Amount of memory allocated for the act run, in megabytes.
      • build ( String ) <optional> - Tag or number of the build to run (e.g. latest or 1.2.34).
      • webhooks ( Array ) <optional> - Specifies optional webhooks associated with the actor run, which can be used to receive a notification e.g. when the actor finished or failed, see ad hook webhooks documentation for detailed description.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( ActRun )
  • updateAct(options, callbackopt) → {Act}

    Updates act.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • actId ( String ) - Unique act ID
      • act ( Object )
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( Act )
  • updateActVersion(options) → {ActVersion}

    Updates 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
      • actVersion ( Object ) - Act version
    Returns:
  • ( ActVersion )
  • ApifyClient.datasets

    Basic usage

    const ApifyClient = require('apify-client');
    
    const apifyClient = new ApifyClient({
           userId: 'RWnGtczasdwP63Mak',
           token: 'f5J7XsdaKDyRywwuGGo9',
    });
    const datasets = apifyClient.datasets;
    
    // Get dataset with name 'my-dataset' and set it as default
    // to be used in following commands.
    const dataset = await datasets.getOrCreateDataset({
        datasetName: 'my-dataset',
    });
    apifyClient.setOptions({ datasetId: dataset.id });
    
    // Save some object and array of objects to dataset.
    await datasets.putItems({
         data: { foo: 'bar' }
    });
    await datasets.putItems({
         data: [{ foo: 'hotel' }, { foo: 'restaurant' }],
    });
    
    // Get items from dataset and delete it.
    const paginationList = await datasets.getItems();
    const items = paginationList.items;
    await datasets.deleteDataset();

    Every method can be used as either promise or with callback. If your Node version supports await/async then you can await promise result.

    // Awaited promise
    try {
         const items = await datasets.getItems();
         // Do something with the items ...
    } catch (err) {
         // Do something with error ...
    }
    
    // Promise
    datasets.getItems()
    .then((paginationList) => {
         console.log(paginationList.items)
         // Do something with items ...
    })
    .catch((err) => {
         // Do something with error ...
    });
    
    // Callback
    datasets.getItems((err, paginationList) => {
         console.log(paginationList.items)
         // Do something with error or items ...
    });

    Methods (7)

    deleteDataset(options, callbackopt) → {*}

    Deletes given dataset.

    Parameters:
    • options ( Object )
      • datasetId ( String ) - Unique dataset ID
      • token ( String ) <optional> - Your API token at apify.com
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( * )
  • getDataset(options, callbackopt) → {Dataset}

    Returns given dataset.

    Parameters:
    • options ( Object )
      • datasetId ( String ) - Unique dataset ID
      • token ( String ) <optional> - Your API token at apify.com
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( Dataset )
  • getItems(options, callbackopt) → {PaginationList}

    Returns items in the dataset based on the provided parameters

    Parameters:
    • options ( Object )
      • datasetId ( String ) - Unique dataset ID
      • format ( String ) <optional> - Format of the items property, possible values are: json, csv, xlsx, html, xml and rss. Defaults to 'json'.
      • 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 250000.
      • desc ( Boolean ) <optional> - If true then the objects are sorted by createdAt in descending order. Otherwise they are sorted in ascending order. Defaults to false.
      • fields ( Array ) <optional> - An array of field names that will be included in the result. If omitted, all fields are included in the results.
      • omit ( Array ) <optional> - An array of field names that will be removed from 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. Defaults to false.
      • attachment ( Boolean ) <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. Defaults to false.
      • delimiter ( String ) <optional> - A delimiter character for CSV files, only used if format is csv. Defaults to ','.
      • bom ( Boolean ) <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. Defaults to '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. Defaults to 'page'.
      • skipHeaderRow ( Boolean ) <optional> - If set to true then header row in CSV format is skipped. Defaults to false.
      • clean ( Boolean ) <optional> - If true then the function returns only non-empty items and skips hidden fields (i.e. fields starting with # character). Note that the clean parameter is a shortcut for skipHidden: true and skipEmpty: true options. Defaults to false.
      • skipHidden ( Boolean ) <optional> - If true then the function doesn't return hidden fields (fields starting with "#" character). Defaults to false.
      • skipEmpty ( Boolean ) <optional> - If true then the function doesn't return empty items. Note that in this case the returned number of items might be lower than limit parameter and pagination must be done using the limit value. Defaults to false.
      • simplified ( Boolean ) <optional> - If true then function applies the fields: ['url','pageFunctionResult','errorInfo'] and unwind: 'pageFunctionResult' options. This feature is used to emulate simplified results provided by Apify API version 1 used for the legacy Apify Crawler and it's not recommended to use it in new integrations.
      • skipFailedPages ( Boolean ) <optional> - If true then, the all the items with errorInfo property will be skipped from the output. This feature is here to emulate functionality of Apify API version 1 used for the legacy Apify Crawler product and it's not recommended to use it in new integrations.
      • 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.
      • token ( String ) <optional> - Your API token at apify.com
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( * )
  • updateDataset(options, callbackopt) → {Dataset}

    Updates dataset.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • datasetId ( String ) - Unique dataset ID
      • dataset ( Object )
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( Dataset )
  • ApifyClient.keyValueStores

    Basic usage

    const ApifyClient = require('apify-client');
    
    const apifyClient = new ApifyClient({
           userId: 'RWnGtczasdwP63Mak',
           token: 'f5J7XsdaKDyRywwuGGo9',
    });
    const keyValueStores = apifyClient.keyValueStores;
    
    const store = await keyValueStores.getOrCreateStore({ storeName: 'my-store' });
    apifyClient.setOptions({ storeId: store.id });
    await keyValueStores.putRecord({
         key: 'foo',
         body: 'bar',
         contentType: 'text/plain; charset=utf-8',
    });
    const record = await keyValueStores.getRecord({ key: 'foo' });
    const keys = await keyValueStores.getRecordsKeys();
    await keyValueStores.deleteRecord({ key: 'foo' });

    Every method can be used as either promise or with callback. If your Node version supports await/async then you can await promise result.

    // Awaited promise
    try {
         const record = await keyValueStores.getRecord({ key: 'foo' });
         // Do something record ...
    } catch (err) {
         // Do something with error ...
    }
    
    // Promise
    keyValueStores.getRecord({ key: 'foo' })
    .then((RECORD) => {
         // Do something record ...
    })
    .catch((err) => {
         // Do something with error ...
    });
    
    // Callback
    keyValueStores.getRecord({ key: 'foo' }, (err, record) => {
         // Do something with error or record ...
    });

    Methods (8)

    deleteRecord(options, callbackopt)

    Deletes given record.

    Parameters:
    • options ( Object )
      • storeId ( String ) - Unique store ID
      • key ( String ) - Key of the record
      • token ( String ) <optional> - Your API token at apify.com
    • callback ( function ) <optional> - Callback function

    deleteStore(options, callbackopt) → {*}

    Deletes 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:
  • ( * )
  • getOrCreateStore(options, callbackopt) → {KeyValueStore}

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

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • storeName ( String ) - Custom unique name to easily identify the store in the future.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( KeyValueStore )
  • getRecord(options, callbackopt) → {KeyValueStoreRecord}

    Gets value stored in the key-value store under the given key.

    Parameters:
    • options ( Object )
      • storeId ( String ) - Unique store ID
      • key ( String ) - Key of the record
      • disableBodyParser ( Boolean ) <optional> - It true, it doesn't parse record's body based on content type.
      • 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.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( Promise.<string> | null )
  • ApifyClient.requestQueues

    Basic usage

    const ApifyClient = require('apify-client');
    
    const apifyClient = new ApifyClient({
           userId: 'RWnGtczasdwP63Mak',
           token: 'f5J7XsdaKDyRywwuGGo9',
    });
    const requestQueues = apifyClient.requestQueues;
    
    // Get request queue with name 'my-queue' and set it as default
    // to be used in following commands.
    const queue = await requestQueues.getOrCreateQueue({
        queueName: 'my-queue',
    });
    apifyClient.setOptions({ queueId: queue.id });
    
    // Add requests to queue.
    await requestQueues.addRequest({ url: 'http://example.com', uniqueKey: 'http://example.com' });
    await requestQueues.addRequest({ url: 'http://example.com/a/b', uniqueKey: 'http://example.com/a/b' });
    
    // Fetch unhandled requets from queue.
    const [request1, request2] = await requestQueues.queryQueueHead();
    
    // Mark request as handled.
    request1.handledAt = new Date();
    await requestQueues.updateRequest(request1);

    Every method can be used as either promise or with callback. If your Node version supports await/async then you can await promise result.

    // Awaited promise
    try {
         const queue = await requestQueues.getQueue(queueId);
         // Do something with the queue ...
    } catch (err) {
         // Do something with error ...
    }
    
    // Promise
    requestQueues.getQueue(queueId)
    .then((queue) => {
         // Do something with queue ...
    })
    .catch((err) => {
         // Do something with error ...
    });
    
    // Callback
    requestQueues.getQueue(queueId, (err, queue) => {
         // Do something with error or queue ...
    });

    Methods (9)

    addRequest(options, callbackopt) → {RequestOperationInfo}

    Adds request to the queue. If request is already in the queue then returns info about existing request.

    Parameters:
    • options ( Object )
      • queueId ( String ) - Unique queue ID
      • request ( Object ) - Request object
      • forefront ( Boolean ) <optional> - If yes then request will be enqueued to the begining of the queue and to the end of the queue otherwise.
      • token ( String ) <optional> - Your API token at apify.com
      • clientKey ( String ) <optional> - Unique ID identifying client accessing the request queue. This ID is used to identify how many clients used the queue. This ID must be a string with length between 1 and 32 characters.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( RequestOperationInfo )
  • deleteQueue(options, callbackopt) → {*}

    Deletes 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:
  • ( * )
  • deleteRequest(options, callbackopt) → {*}

    Deletes request from queue.

    Parameters:
    • options ( Object )
      • queueId ( String ) - Unique queue ID
      • requestId ( String ) - Unique request ID
      • token ( String ) <optional> - Your API token at apify.com
      • clientKey ( String ) <optional> - Unique ID identifying client accessing the request queue. This ID is used to identify how many clients used the queue. This ID must be a string with length between 1 and 32 characters.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( * )
  • getHead(options, callbackopt) → {QueueHead}

    Returns given number of the first unhandled requests in he queue.

    Parameters:
    • options ( Object )
      • queueId ( String ) - Unique queue ID
      • limit ( Number ) - Maximum number of the items to be returned.
      • token ( String ) <optional> - Your API token at apify.com
      • clientKey ( String ) <optional> - Unique ID identifying client accessing the request queue. This ID is used to identify how many clients used the queue. This ID must be a string with length between 1 and 32 characters.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( QueueHead )
  • 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.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( PaginationList )
  • updateRequest(options, callbackopt) → {RequestOperationInfo}

    Updates request in the queue.

    Parameters:
    • options ( Object )
      • queueId ( String ) - Unique queue ID
      • request ( Object ) - Request object
      • requestId ( String ) <optional> - Unique request ID
      • forefront ( Boolean ) <optional> - If yes then request will be enqueued to the begining of the queue and to the end of the queue otherwise.
      • token ( String ) <optional> - Your API token at apify.com
      • clientKey ( String ) <optional> - Unique ID identifying client accessing the request queue. This ID is used to identify how many clients used the queue. This ID must be a string with length between 1 and 32 characters.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( RequestOperationInfo )
  • ApifyClient.tasks

    Basic usage

    Every method can be used as either promise or with callback. If your Node version supports await/async then you can await promise result.

    const ApifyClient = require('apify-client');
    
    const apifyClient = new ApifyClient({
     userId: 'jklnDMNKLekk',
     token: 'SNjkeiuoeD443lpod68dk',
    });
    
    // Awaited promise
    try {
         const tasksList = await apifyClient.tasks.listTasks({});
         // Do something with the tasksList ...
    } catch (err) {
         // Do something with error ...
    }
    
    // Promise
    apifyClient.tasks.listTasks({})
    .then((tasksList) => {
         // Do something tasksList ...
    })
    .catch((err) => {
         // Do something with error ...
    });
    
    // Callback
    apifyClient.tasks.listTasks({}, (err, tasksList) => {
         // Do something with error or tasksList ...
    });

    Methods (9)

    createTask(options, callbackopt) → {Task}

    Creates a new task.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • task ( Object ) - Object containing configuration of the task
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( Task )
  • deleteTask(options, callbackopt)

    Deletes task.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • taskId ( String ) - Unique task ID
    • callback ( function ) <optional> - Callback function

    getInput(options, callbackopt) → {Object}

    Gets the actor task input.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • taskId ( String ) - Unique task ID
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( Object )
  • getTask(options, callbackopt) → {Task}

    Gets task object.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • taskId ( String ) - Unique task ID
    • callback ( function ) <optional> - Callback function
    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.
      • input ( Object ) <optional> - Actor task input object.
      • timeout ( Number ) <optional> - Timeout for the act run in seconds. Zero value means there is no timeout.
      • memory ( Number ) <optional> - Amount of memory allocated for the act run, in megabytes.
      • build ( String ) <optional> - Tag or number of the build to run (e.g. latest or 1.2.34).
      • webhooks ( Array ) <optional> - Specifies optional webhooks associated with the actor run, which can be used to receive a notification e.g. when the actor finished or failed, see ad hook webhooks documentation for detailed description.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( ActRun )
  • updateInput(options, callbackopt) → {Object}

    Updates the actor task input.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • taskId ( String ) - Unique task ID
      • input ( Object ) - Input object.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( Object )
  • updateTask(options, callbackopt) → {Task}

    Updates task.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • taskId ( String ) - Unique task ID
      • task ( Object )
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( Task )
  • ApifyClient.users

    Users

    Methods (1)

    getUser(options, callbackopt) → {UserInfo}

    Returns private and public information about user account.

    Parameters:
    • options ( Object )
      • token ( String ) <optional> - If set, the function returns a private and public information for the user account, otherwise it only returns public information.
      • userId ( String ) <optional> - Desired user ID or username. By default it is 'me', which causes the function to return information about the current user. Defaults to 'me'.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( UserInfo )
  • ApifyClient.webhookDispatches

    Basic usage

    Every method can be used as either promise or with callback. If your Node version supports await/async then you can await promise result.

    const ApifyClient = require('apify-client');
    
    const apifyClient = new ApifyClient({
     userId: 'jklnDMNKLekk',
     token: 'SNjkeiuoeD443lpod68dk',
    });
    
    // Awaited promise
    try {
         const dispatchesList = await apifyClient.webhookDispatches.listWebhookDispatches({});
         // Do something with the list ...
    } catch (err) {
         // Do something with error ...
    }
    
    // Promise
    apifyClient.webhookDispatches.listWebhookDispatches({})
    .then((webhooksList) => {
         // Do something with the list ...
    })
    .catch((err) => {
         // Do something with error ...
    });
    
    // Callback
    apifyClient.webhookDispatches.listWebhookDispatches({}, (err, webhooksList) => {
         // Do something with error or list ...
    });

    Methods (2)

    getDispatch(options, callbackopt) → {WebhookDispatch}

    Gets webhook dispatch.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • webhookDispatchId - Webhook dispatch ID
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( WebhookDispatch )
  • listDispatches(options, callbackopt) → {PaginationList}

    By default, the objects are sorted by the startedAt field in ascending order, therefore you can use pagination to incrementally fetch all dispatches. 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 startedAd field in descending order.
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( PaginationList )
  • ApifyClient.webhooks

    Basic usage

    Every method can be used as either promise or with callback. If your Node version supports await/async then you can await promise result.

    const ApifyClient = require('apify-client');
    
    const apifyClient = new ApifyClient({
     userId: 'jklnDMNKLekk',
     token: 'SNjkeiuoeD443lpod68dk',
    });
    
    // Awaited promise
    try {
         const webhooks = await apifyClient.webhooks.listWebhooks({});
         // Do something with list ...
    } catch (err) {
         // Do something with error ...
    }
    
    // Promise
    apifyClient.webhooks.listWebhooks({})
    .then((webhooksList) => {
         // Do something with list ...
    })
    .catch((err) => {
         // Do something with error ...
    });
    
    // Callback
    apifyClient.webhooks.listWebhooks({}, (err, webhooksList) => {
         // Do something with error or list ...
    });

    Methods (6)

    createWebhook(options, callbackopt) → {Webhook}

    Creates new webhook.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • webhook - Webhook
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( Webhook )
  • deleteWebhook(options, callbackopt)

    Deletes webhook.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • webhookId - Webhook ID
    • callback ( function ) <optional> - Callback function
    Returns:

    getWebhook(options, callbackopt) → {Webhook}

    Gets webhook object.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • webhookId - Webhook ID
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( Webhook )
  • listDispatches(options, callbackopt) → {PaginationList}

    By default, the objects are sorted by the createdAt.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • webhookId - Webhook 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 )
  • listWebhooks(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 webhooks. To sort them in descending order, use desc: true parameter.

    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 )
  • updateWebhook(options, callbackopt) → {Webhook}

    Updates webhook.

    Parameters:
    • options ( Object )
      • token ( String ) - Your API token at apify.com
      • webhookId - Webhook ID
      • webhook - Webhook
    • callback ( function ) <optional> - Callback function
    Returns:
  • ( Webhook )
  • Globals

    Type Definitions

    QueueHead

    Properties:
    • limit ( Number ) - Maximum number of items to be returned.
    • queueModifiedAt ( Date ) - Date of the last modification of the queue.
    • items ( Array ) - Array of objects containing id, url, method, uniqueKey and retryCount attributes.

    RequestOperationInfo

    Properties:
    • wasAlreadyPresent ( Boolean ) - Indicates if request was already present in the queue.
    • wasAlreadyHandled ( Boolean ) - Indicates if request was already marked as handled.
    • requestId ( String ) - The ID of the added request