RequestQueueClient
Hierarchy
- ResourceClient
- RequestQueueClient
Index
Properties
inheritedapifyClient
inheritedbaseUrl
inheritedhttpClient
optionalinheritedid
optionalinheritedparams
inheritedpublicBaseUrl
inheritedresourcePath
optionalinheritedsafeId
inheritedurl
Methods
addRequest
Adds a single request to the queue.
If a request with the same
uniqueKeyalready exists, the method will return information about the existing request without adding a duplicate. TheuniqueKeyis used for deduplication - typically it's the URL, but you can use any string to identify the request.Parameters
request: Omit<RequestQueueClientRequestSchema, id>
The request object to add (excluding
id, which is assigned by the API)options: RequestQueueClientAddRequestOptions = {}
Additional options
Returns Promise<RequestQueueClientAddRequestResult>
Object with
requestId,wasAlreadyPresent, andwasAlreadyHandledflags
batchAddRequests
Adds multiple requests to the queue in a single operation.
This is significantly more efficient than calling addRequest multiple times, especially for large batches. The method automatically handles batching (max 25 requests per API call), retries on rate limiting, and parallel processing. Requests are sent in chunks respecting the API payload size limit, and any unprocessed requests due to rate limits are automatically retried with exponential backoff.
Parameters
requests: Omit<RequestQueueClientRequestSchema, id>[]
Array of request objects to add (excluding
idfields)options: RequestQueueClientBatchAddRequestWithRetriesOptions = {}
Batch operation configuration
Returns Promise<RequestQueueClientBatchRequestsOperationResult>
Object with
processedRequests(successfully added) andunprocessedRequests(failed after all retries)
batchDeleteRequests
Deletes multiple requests from the queue in a single operation.
Requests can be identified by either their ID or unique key.
Parameters
requests: RequestQueueClientRequestToDelete[]
Array of requests to delete (by id or uniqueKey)
Returns Promise<RequestQueueClientBatchRequestsOperationResult>
Result containing processed and unprocessed requests
delete
Deletes the Request queue.
Returns Promise<void>
deleteRequest
Deletes a specific request from the queue.
Parameters
id: string
Request ID
Returns Promise<void>
deleteRequestLock
Releases the lock on a request, allowing other clients to process it.
This should be called after successfully processing a request or when you decide not to process it.
Parameters
id: string
Request ID
options: RequestQueueClientDeleteRequestLockOptions = {}
Options such as whether to move to front
Returns Promise<void>
get
Gets the Request queue object from the Apify API.
Returns Promise<undefined | RequestQueue>
The RequestQueue object, or
undefinedif it does not exist
getRequest
Gets a specific request from the queue by its ID.
Parameters
id: string
Request ID
Returns Promise<undefined | RequestQueueClientGetRequestResult>
The request object, or
undefinedif not found
listAndLockHead
Gets and locks the next requests from the queue head for processing.
This method retrieves requests from the beginning of the queue and locks them for the specified duration to prevent other clients from processing them simultaneously. This is the primary method used by distributed web crawlers to coordinate work across multiple workers. Locked requests won't be returned to other clients until the lock expires or is explicitly released using deleteRequestLock.
Parameters
options: RequestQueueClientListAndLockHeadOptions
Lock configuration
Returns Promise<RequestQueueClientListAndLockHeadResult>
Object containing
items(locked requests),queueModifiedAt,hadMultipleClients, and lock information
listHead
Lists requests from the beginning of the queue (head).
Returns the first N requests from the queue without locking them. This is useful for inspecting what requests are waiting to be processed.
Parameters
options: RequestQueueClientListHeadOptions = {}
Options for listing (e.g., limit)
Returns Promise<RequestQueueClientListHeadResult>
List of requests from the queue head
listRequests
Lists all requests in the queue.
Returns a paginated list of all requests, allowing you to iterate through the entire queue contents.
Parameters
options: RequestQueueClientListRequestsOptions = {}
Pagination options
Returns Promise<RequestQueueClientListRequestsResult> & AsyncIterable<RequestQueueClientRequestSchema, any, any>
List of requests with pagination information
paginateRequests
Returns an async iterable for paginating through all requests in the queue.
This allows you to efficiently process all requests using a for-await-of loop, automatically handling pagination behind the scenes.
Parameters
options: RequestQueueClientPaginateRequestsOptions = {}
Pagination options
Returns RequestQueueRequestsAsyncIterable<RequestQueueClientListRequestsResult>
An async iterable of request pages
prolongRequestLock
Prolongs the lock on a request to prevent it from being returned to other clients.
This is useful when processing a request takes longer than expected and you need to extend the lock duration to prevent other workers from picking it up. The lock expiration time is reset to the current time plus the specified duration.
Parameters
id: string
Request ID (obtained from listAndLockHead or getRequest)
options: RequestQueueClientProlongRequestLockOptions
Lock extension options
Returns Promise<RequestQueueClientProlongRequestLockResult>
Object with new
lockExpiresAttimestamp
unlockRequests
Unlocks all requests locked by this client.
This is useful for releasing all locks at once, for example when shutting down a crawler gracefully.
Returns Promise<RequestQueueClientUnlockRequestsResult>
Number of requests that were unlocked
update
Updates the Request queue with specified fields.
Parameters
newFields: RequestQueueClientUpdateOptions
Fields to update in the Request queue
Returns Promise<RequestQueue>
The updated RequestQueue object
updateRequest
Updates a request in the queue.
Parameters
request: RequestQueueClientRequestSchema
The updated request object (must include id)
options: RequestQueueClientAddRequestOptions = {}
Update options such as whether to move to front
Returns Promise<RequestQueueClientAddRequestResult>
Information about the updated request
Client for managing a specific Request queue.
Request queues store URLs to be crawled and their metadata. Each request in the queue has a unique ID and can be in various states (pending, handled). This client provides methods to add, get, update, and delete requests, as well as manage the queue itself.
https://docs.apify.com/platform/storage/request-queue