DatasetClient <Data>
Hierarchy
- ResourceClient
- DatasetClient
Index
Properties
inheritedapifyClient
inheritedbaseUrl
inheritedhttpClient
optionalinheritedid
optionalinheritedparams
inheritedpublicBaseUrl
inheritedresourcePath
optionalinheritedsafeId
inheritedurl
Methods
createItemsPublicUrl
Generates a public URL for accessing dataset items.
If the client has permission to access the dataset's URL signing key, the URL will include a cryptographic signature allowing access without authentication. This is useful for sharing dataset results with external services or users.
Parameters
options: DatasetClientCreateItemsUrlOptions = {}
URL generation options (extends all options from listItems)
Returns Promise<string>
A public URL string for accessing the dataset items
// Create a URL that expires in 1 hour with specific fieldsconst url = await client.dataset('my-dataset').createItemsPublicUrl({expiresInSecs: 3600,fields: ['url', 'title'],limit: 100});console.log(`Share this URL: ${url}`);// Create a permanent public URL for clean items onlyconst url = await client.dataset('my-dataset').createItemsPublicUrl({clean: true,skipEmpty: true});
delete
Deletes the dataset.
Returns Promise<void>
See more at https://docs.apify.com/api/v2/dataset-delete
downloadItems
Downloads dataset items in a specific format.
Unlike listItems which returns a PaginatedList with an array of individual dataset items, this method returns the items serialized to the provided format (JSON, CSV, Excel, etc.) as a Buffer. Useful for exporting data for further processing.
Parameters
format: DownloadItemsFormat
Output format:
'json','jsonl','csv','xlsx','xml','rss', or'html'options: DatasetClientDownloadItemsOptions = {}
Download and formatting options (extends all options from listItems)
Returns Promise<Buffer<ArrayBufferLike>>
Buffer containing the serialized data in the specified format
// Download as CSV with BOM for Excel compatibilityconst csvBuffer = await client.dataset('my-dataset').downloadItems('csv', { bom: true });require('fs').writeFileSync('output.csv', csvBuffer);// Download as Excel with custom optionsconst xlsxBuffer = await client.dataset('my-dataset').downloadItems('xlsx', {fields: ['url', 'title', 'price'],skipEmpty: true,limit: 1000});// Download as XML with custom element namesconst xmlBuffer = await client.dataset('my-dataset').downloadItems('xml', {xmlRoot: 'products',xmlRow: 'product'});See more at https://docs.apify.com/api/v2/dataset-items-get
get
Gets the dataset object from the Apify API.
Returns Promise<undefined | Dataset>
The Dataset object, or
undefinedif it does not existSee more at https://docs.apify.com/api/v2/dataset-get
getStatistics
Gets statistical information about the dataset.
Returns statistics for each field in the dataset, including information about data types, null counts, and value ranges.
Returns Promise<undefined | DatasetStatistics>
Dataset statistics, or
undefinedif not available
listItems
Lists items in the dataset.
Returns a paginated list of dataset items. You can use pagination parameters to retrieve specific subsets of items, and various filtering and formatting options to customize the output.
Parameters
options: DatasetClientListItemOptions = {}
Options for listing items
Returns PaginatedIterator<Data>
A paginated list with
items,totalcount,offset,count, andlimit// Get first 100 itemsconst { items, total } = await client.dataset('my-dataset').listItems({ limit: 100 });console.log(`Retrieved ${items.length} of ${total} total items`);// Get items with specific fields onlyconst { items } = await client.dataset('my-dataset').listItems({fields: ['url', 'title'],skipEmpty: true,limit: 50});// Get items in descending order with paginationconst { items } = await client.dataset('my-dataset').listItems({desc: true,offset: 100,limit: 50});See more at https://docs.apify.com/api/v2/dataset-items-get
pushItems
Stores one or more items into the dataset.
Items can be objects, strings, or arrays thereof. Each item will be stored as a separate record in the dataset. Objects are automatically serialized to JSON. If you provide an array, all items will be stored in order. This method is idempotent - calling it multiple times with the same data will not create duplicates, but will append items each time.
Parameters
items: string | Data | string[] | Data[]
A single item (object or string) or an array of items to store. Objects are automatically stringified to JSON. Strings are stored as-is.
Returns Promise<void>
// Store a single objectawait client.dataset('my-dataset').pushItems({url: 'https://example.com',title: 'Example Page',extractedAt: new Date()});// Store multiple items at onceawait client.dataset('my-dataset').pushItems([{ url: 'https://example.com', title: 'Example' },{ url: 'https://test.com', title: 'Test' },{ url: 'https://demo.com', title: 'Demo' }]);// Store string itemsawait client.dataset('my-dataset').pushItems(['item1', 'item2', 'item3']);See more at https://docs.apify.com/api/v2/dataset-items-post
update
Updates the dataset with specified fields.
Parameters
newFields: DatasetClientUpdateOptions
Fields to update in the dataset
Returns Promise<Dataset>
The updated Dataset object
See more at https://docs.apify.com/api/v2/dataset-put
Client for managing a specific Dataset.
Datasets store structured data results from Actor runs. This client provides methods to push items, list and retrieve items, download items in various formats (JSON, CSV, Excel, etc.), and manage the dataset.