Provides API endpoints related to api/tasks
Summary
Functions
Create Actor task
Delete Actor task
Get Actor task
Get list of Actor tasks
Run Actor task synchronously and get key-value store record
Run Actor task synchronously and get dataset items
Update Actor task
Types
@type get_200_json_resp() :: %{data: ApifyClient.Schemas.Task.t()}
@type update_200_json_resp() :: %{data: ApifyClient.Schemas.Task.t()}
Functions
@spec create(body :: map(), opts :: keyword()) :: {:ok, ApifyClient.Schemas.Task.t()} | {:error, ApifyClient.Error.t()}
Create Actor task
Create a new task with settings specified by the object passed as JSON in the POST payload.
The response is the full task object as returned by the Get Actor task endpoint.
The request needs to specify the Content-Type: application/json HTTP header!
When providing your API authentication token, we recommend using the
request's Authorization header, rather than the URL.
Request Body
Content Types: application/json
@spec delete(actor_task_id :: String.t(), opts :: keyword()) :: :ok | {:error, ApifyClient.Error.t()}
Delete Actor task
Delete the task specified through the actorTaskId parameter.
@spec get(actor_task_id :: String.t(), opts :: keyword()) :: {:ok, ApifyClient.Schemas.Task.t()} | {:error, ApifyClient.Error.t()}
Get Actor task
Get an object that contains all the details about a task.
@spec list(opts :: keyword()) :: {:ok, ApifyClient.Schemas.ListOfTasks.t()} | {:error, ApifyClient.Error.t()}
Get list of Actor tasks
Gets the complete list of tasks that a user has created or used.
The response is a list of objects in which each object contains essential information about a single task.
The endpoint supports pagination using the limit and offset parameters,
and it does not return more than a 1000 records.
By default, the records 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 the records in descending order, use
the desc=1 parameter.
Options
offset: Number of items that should be skipped at the start. The default value is0.limit: Maximum number of items to return. The default value as well as the maximum is1000.desc: Iftrueor1then the objects are sorted by thecreatedAtfield in descending order. By default, they are sorted in ascending order.
@spec run_sync(actor_task_id :: String.t(), body :: any(), opts :: keyword()) :: {:ok, any()} | {:error, ApifyClient.Error.t()}
Run Actor task synchronously and get key-value store record
Runs an Actor task and synchronously returns a key-value store record.
The response contains the record stored under the OUTPUT key in the run's
default key-value store. This is a legacy approach that has been replaced by
the Actor output object;
Actors aren't required to store a record under this key, so the response may
not contain any data. Use the outputRecordKey query parameter to return a
different record.
The run must finish in 300<!-- MAX_ACTOR_JOB_SYNC_WAIT_SECS --> seconds otherwise the HTTP request fails with a timeout error (this won't abort the run itself).
Optionally, you can override the Actor input configuration by passing a JSON
object as the POST payload and setting the Content-Type: application/json HTTP header.
Note that if the object in the POST payload does not define a particular input property, the Actor run uses the default value defined by the task (or Actor's input schema if not defined by the task).
Beware that it might be impossible to maintain an idle HTTP connection for an extended period, due to client timeout or network conditions. Make sure your HTTP client is configured to have a long enough connection timeout.
If the connection breaks, you will not receive any information about the run and its status.
Input fields from Actor task configuration can be overloaded with values passed as the POST payload.
Just make sure to specify Content-Type header to be application/json and
input to be an object.
To run the task asynchronously, use the Run Actor task API endpoint instead.
Options
timeout: Optional timeout for the run, in seconds. By default, the run uses the timeout from its configuration.memory: Memory limit for the run, in megabytes. You can set the amount of memory to a power of 2 with a minimum of 128. By default, the run uses the memory limit from its configuration. Don't change this value unless the Actor's documentation recommends it or you're aware of the consequences.max_items: Specifies the maximum number of dataset items that will be charged for pay-per-result Actors. This does NOT guarantee that the Actor will return only this many items. It only ensures you won't be charged for more than this number of items. Only works for pay-per-result Actors. Value can be accessed in the actor run usingACTOR_MAX_PAID_DATASET_ITEMSenvironment variable.max_total_charge_usd: Specifies the maximum total cost of the run. Use it to cap the total amount charged for all pricing models. You can access the maximum cost in your Actor by using theACTOR_MAX_TOTAL_CHARGE_USDenvironment variable.restart_on_error: Determines whether the run will be restarted if it fails.build: Specifies the Actor build to run. It can be either a build tag or build number. By default, the run uses the build from its configuration (typicallylatest).output_record_key: Key of the record from the run's default key-value store to return in the response. Defaults toOUTPUT. Actors aren't required to store a record under this key, so if it doesn't exist the response contains no data.webhooks: Specifies optional webhooks associated with the Actor run, which can be used to receive a notification e.g. when the Actor finished or failed. The value is a Base64-encoded JSON array whose items follow the WebhookRepresentation schema. For more information, see Webhooks documentation.
Request Body
Content Types: */*, application/json
@spec run_sync_get_dataset_items( actor_task_id :: String.t(), body :: any(), opts :: keyword() ) :: {:ok, map() | nil} | {:error, ApifyClient.Error.t()}
Run Actor task synchronously and get dataset items
Runs an Actor task and synchronously returns its dataset items.
The run must finish in 300<!-- MAX_ACTOR_JOB_SYNC_WAIT_SECS --> seconds otherwise the HTTP request fails with a timeout error (this won't abort the run itself).
Optionally, you can override the Actor input configuration by passing a JSON
object as the POST payload and setting the Content-Type: application/json HTTP header.
Note that if the object in the POST payload does not define a particular input property, the Actor run uses the default value defined by the task (or the Actor's input schema if not defined by the task).
You can send all the same options in parameters as the Get dataset items API endpoint.
Beware that it might be impossible to maintain an idle HTTP connection for an extended period, due to client timeout or network conditions. Make sure your HTTP client is configured to have a long enough connection timeout.
If the connection breaks, you will not receive any information about the run and its status.
Input fields from Actor task configuration can be overloaded with values passed as the POST payload.
Just make sure to specify the Content-Type header as application/json
and that the input is an object.
To run the task asynchronously, use the Run Actor task API endpoint instead.
Options
timeout: Optional timeout for the run, in seconds. By default, the run uses the timeout from its configuration.memory: Memory limit for the run, in megabytes. You can set the amount of memory to a power of 2 with a minimum of 128. By default, the run uses the memory limit from its configuration. Don't change this value unless the Actor's documentation recommends it or you're aware of the consequences.max_items: Specifies the maximum number of dataset items that will be charged for pay-per-result Actors. This does NOT guarantee that the Actor will return only this many items. It only ensures you won't be charged for more than this number of items. Only works for pay-per-result Actors. Value can be accessed in the actor run usingACTOR_MAX_PAID_DATASET_ITEMSenvironment variable.max_total_charge_usd: Specifies the maximum total cost of the run. Use it to cap the total amount charged for all pricing models. You can access the maximum cost in your Actor by using theACTOR_MAX_TOTAL_CHARGE_USDenvironment variable.restart_on_error: Determines whether the run will be restarted if it fails.build: Specifies the Actor build to run. It can be either a build tag or build number. By default, the run uses the build from its configuration (typicallylatest).webhooks: Specifies optional webhooks associated with the Actor run, which can be used to receive a notification e.g. when the Actor finished or failed. The value is a Base64-encoded JSON array whose items follow the WebhookRepresentation schema. For more information, see Webhooks documentation.format: Format of the results, possible values are:json,jsonl,csv,html,xlsx,xmlandrss. The default value isjson.clean: Iftrueor1then the API endpoint returns only non-empty items and skips hidden fields (i.e. fields starting with the # character). Thecleanparameter is just a shortcut forskipHidden=trueandskipEmpty=trueparameters. Note that since some objects might be skipped from the output, that the result might contain less items than thelimitvalue.offset: Number of items that should be skipped at the start. The default value is0.limit: Maximum number of items to return. By default there is no limit.fields: A comma-separated list of fields which should be picked from the items, only these fields will remain in the resulting record objects. Note that the fields in the outputted items are sorted the same way as they are specified in thefieldsquery parameter. You can use this feature to effectively fix the output format.output_fields: A comma-separated list of output field names that positionally rename the fields specified in thefieldsparameter. For example,?fields=headline,url&outputFields=title,linkrenamesheadlinetotitleandurltolinkin the output. The number of names inoutputFieldsmust match the number of names infields. Requires thefieldsparameter to be specified as well.omit: A comma-separated list of fields which should be omitted from the items.unwind: A comma-separated list of fields which should be unwound, in order which they should be processed. Each field should be either an array or an object. If the field is an array then every element of the array will become a separate record and merged with parent object. If the unwound field is an object then it is merged with the parent object. If the unwound field is missing or its value is neither an array nor an object and therefore cannot be merged with a parent object then the item gets preserved as it is. Note that the unwound items ignore thedescparameter.flatten: A comma-separated list of fields which should transform nested objects into flat structures.For example, with
flatten="foo"the object{"foo":{"bar": "hello"}}is turned into{"foo.bar": "hello"}.The original object with properties is replaced with the flattened object.
desc: By default, results are returned in the same order as they were stored. To reverse the order, set this parameter totrueor1.attachment: Iftrueor1then the response will define theContent-Disposition: attachmentheader, forcing a web browser to download the file rather than to display it. By default this header is not present.delimiter: A delimiter character for CSV files, only used ifformat=csv. You might need to URL-encode the character (e.g. use%09for tab or%3Bfor semicolon). The default delimiter is a simple comma (,).bom: All text responses are encoded in UTF-8 encoding. By default, theformat=csvfiles are prefixed with the UTF-8 Byte Order Mark (BOM), whilejson,jsonl,xml,htmlandrssfiles are not.If you want to override this default behavior, specify
bom=1query parameter to include the BOM orbom=0to skip it.xml_root: Overrides default root element name ofxmloutput. By default the root element isitems.xml_row: Overrides default element name that wraps each page or page function result object inxmloutput. By default the element name isitem.skip_header_row: Iftrueor1then header row in thecsvformat is skipped.skip_hidden: Iftrueor1then hidden fields are skipped from the output, i.e. fields starting with the#character.skip_empty: Iftrueor1then empty items are skipped from the output.Note that if used, the results might contain less items than the limit value.
simplified: Iftrueor1then, the endpoint applies thefields=url,pageFunctionResult,errorInfoandunwind=pageFunctionResultquery parameters. This feature is used to emulate simplified results provided by the legacy Apify Crawler product and it's not recommended to use it in new integrations.view: Defines the view configuration for dataset items based on the schema definition. This parameter determines how the data will be filtered and presented. For complete specification details, see the dataset schema documentation.skip_failed_pages: Iftrueor1then, the all the items with errorInfo property will be skipped from the output.This feature is here to emulate functionality of API version 1 used for the legacy Apify Crawler product and it's not recommended to use it in new integrations.
feed_title: Overrides the auto-generated RSS channel<title>element. Only used whenformat=rss. If not provided, the title defaults toDataset <label>.feed_description: Overrides the auto-generated RSS channel<description>element. Only used whenformat=rss. If not provided, the description defaults toItems in dataset with id "<datasetId>".
Request Body
Content Types: */*, application/json
@spec update( actor_task_id :: String.t(), body :: map() | ApifyClient.Schemas.UpdateTaskRequest.t(), opts :: keyword() ) :: {:ok, ApifyClient.Schemas.Task.t()} | {:error, ApifyClient.Error.t()}
Update Actor task
Update settings of a task using values specified by an object passed as JSON in the POST payload.
If the object does not define a specific property, its value is not updated.
The publicConfig field carries the display configuration of the task's public
landing page, and isPublic publishes or unpublishes the task itself. Both require
write permission to the task's Actor.
To publish a task, its Actor must be public and both publicConfig.inputSchemaFields and
publicConfig.datasetView must be set. Note that an Actor can have up to 10 published tasks
and your account up to 100.
If the task doesn't meet all these conditions, the request fails and no fields are updated,
including those unrelated to publishing.
Publishing lists the task among the Actor's examples and makes its input public, so anyone
can view and copy it. The landing page itself is shown only while publicConfig still
validates against the Actor's current build, so a new build can stop the page from being
offered while the task stays published and copyable.
The response is the full task object as returned by the Get Actor task endpoint.
The request needs to specify the Content-Type: application/json HTTP
header!
When providing your API authentication token, we recommend using the
request's Authorization header, rather than the URL.
Request Body
Content Types: application/json