ApifyClient.API.Actors (apify_client v1.0.0)

Copy Markdown View Source

Provides API endpoints related to api/actors

Summary

Functions

Get list of Actors

Run Actor synchronously and get key-value store record

Run Actor synchronously and get dataset items

Types

validate_input_200_json_resp()

@type validate_input_200_json_resp() :: %{valid: boolean()}

Functions

create(body, opts \\ [])

@spec create(
  body :: map() | ApifyClient.Schemas.CreateActorRequest.t(),
  opts :: keyword()
) ::
  {:ok, ApifyClient.Schemas.ActorResource.t()} | {:error, ApifyClient.Error.t()}

Create Actor

Creates an Actor with the settings specified in an Actor object passed as JSON in the POST payload.

Returns the created Actor object.

In the HTTP request, set the Content-Type header to application/json.

Define a source code version

An Actor must specify at least one version of the source code. For details, see Actor versions.

Publish an Actor

To make your Actor public, use the Update Actor endpoint.

Request Body

Content Types: application/json

delete(actor_id, opts \\ [])

@spec delete(actor_id :: String.t(), opts :: keyword()) ::
  :ok | {:error, ApifyClient.Error.t()}

Delete Actor

Deletes an Actor with the specified ID.

get(actor_id, opts \\ [])

@spec get(actor_id :: String.t(), opts :: keyword()) ::
  {:ok, ApifyClient.Schemas.ActorResource.t()} | {:error, ApifyClient.Error.t()}

Get Actor

Gets an object that contains all the details about the Actor with the specified ID.

list(opts \\ [])

@spec list(opts :: keyword()) ::
  {:ok, ApifyClient.Schemas.ListOfActors.t()} | {:error, ApifyClient.Error.t()}

Get list of Actors

Gets the list of all Actors that the user created or used. The response is a list of objects, where each object contains a basic information about a single Actor.

To only get Actors created by the user, add the my=1 query parameter.

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

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

You can also sort by your last run by using the sortBy=stats.lastRunStartedAt query parameter. In this case, descending order means the most recently run Actor appears first.

Options

  • my: If true or 1 then the returned list only contains Actors owned by the user. The default value is false.

  • offset: Number of items that should be skipped at the start. The default value is 0.

  • limit: Maximum number of items to return. The default value as well as the maximum is 1000.

  • desc: If true or 1 then the objects are sorted by the createdAt field in descending order. By default, they are sorted in ascending order.

  • sort_by: Field to sort the records by. The default is createdAt. You can also use stats.lastRunStartedAt to sort by the most recently ran Actors.

run_sync(actor_id, body, opts \\ [])

@spec run_sync(actor_id :: String.t(), body :: any(), opts :: keyword()) ::
  {:ok, any()} | {:error, ApifyClient.Error.t()}

Run Actor synchronously and get key-value store record

Runs a specific Actor and returns a key-value store record.

The POST payload including its Content-Type header is passed as INPUT to the Actor (usually <code>application/json</code>).

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 Actor is started with the default options; you can override them using various URL query parameters. If the Actor run exceeds 300<!-- MAX_ACTOR_JOB_SYNC_WAIT_SECS --> seconds, the HTTP response will have status 408 (Request Timeout).

Beware that it might be impossible to maintain an idle HTTP connection for a long period of time, 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.

To run the Actor asynchronously, use the Run Actor API endpoint instead.

Options

  • output_record_key: Key of the record from the run's default key-value store to return in the response. Defaults to OUTPUT. Actors aren't required to store a record under this key, so if it doesn't exist the response contains no data.

  • 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 using ACTOR_MAX_PAID_DATASET_ITEMS environment 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 the ACTOR_MAX_TOTAL_CHARGE_USD environment 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 (typically latest).

  • 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.

  • force_permission_level: Overrides the Actor's permission level for this specific run. Use to test restricted permissions before deploying changes to your Actor or to temporarily elevate or restrict access. If you don't specify this parameter, the Actor uses its configured default permission level. For more information on permissions, see the documentation.

Request Body

Content Types: */*, application/json

run_sync_get_dataset_items(actor_id, body, opts \\ [])

@spec run_sync_get_dataset_items(
  actor_id :: String.t(),
  body :: any(),
  opts :: keyword()
) ::
  {:ok, [map()]} | {:error, ApifyClient.Error.t()}

Run Actor synchronously and get dataset items

Runs a specific Actor and returns its dataset items.

The POST payload including its Content-Type header is passed as INPUT to the Actor (usually application/json). The HTTP response contains the Actors dataset items, while the format of items depends on specifying dataset items' format parameter.

You can send all the same options in parameters as the Get dataset items API endpoint.

The Actor is started with the default options; you can override them using URL query parameters. If the Actor run exceeds 300<!-- MAX_ACTOR_JOB_SYNC_WAIT_SECS --> seconds, the HTTP response will return the 408 status code (Request Timeout).

Beware that it might be impossible to maintain an idle HTTP connection for a long period of time, 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.

To run the Actor asynchronously, use the Run Actor 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 using ACTOR_MAX_PAID_DATASET_ITEMS environment 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 the ACTOR_MAX_TOTAL_CHARGE_USD environment 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 (typically latest).

  • 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.

  • force_permission_level: Overrides the Actor's permission level for this specific run. Use to test restricted permissions before deploying changes to your Actor or to temporarily elevate or restrict access. If you don't specify this parameter, the Actor uses its configured default permission level. For more information on permissions, see the documentation.

  • format: Format of the results, possible values are: json, jsonl, csv, html, xlsx, xml and rss. The default value is json.

  • clean: If true or 1 then the API endpoint returns only non-empty items and skips hidden fields (i.e. fields starting with the # character). The clean parameter is just a shortcut for skipHidden=true and skipEmpty=true parameters. Note that since some objects might be skipped from the output, that the result might contain less items than the limit value.

  • offset: Number of items that should be skipped at the start. The default value is 0.

  • 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 the fields query 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 the fields parameter. For example, ?fields=headline,url&outputFields=title,link renames headline to title and url to link in the output. The number of names in outputFields must match the number of names in fields. Requires the fields parameter 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 the desc parameter.

  • 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 to true or 1.

  • attachment: If true or 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: 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). The default delimiter is a simple comma (,).

  • bom: All text responses are encoded in UTF-8 encoding. By default, the format=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.

  • xml_root: Overrides default root element name of xml output. By default the root element is items.

  • xml_row: Overrides default element name that wraps each page or page function result object in xml output. By default the element name is item.

  • skip_header_row: If true or 1 then header row in the csv format is skipped.

  • skip_hidden: If true or 1 then hidden fields are skipped from the output, i.e. fields starting with the # character.

  • skip_empty: If true or 1 then empty items are skipped from the output.

    Note that if used, the results might contain less items than the limit value.

  • simplified: If true or 1 then, the endpoint applies the fields=url,pageFunctionResult,errorInfo and unwind=pageFunctionResult query 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: If true or 1 then, 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 when format=rss. If not provided, the title defaults to Dataset <label>.

  • feed_description: Overrides the auto-generated RSS channel <description> element. Only used when format=rss. If not provided, the description defaults to Items in dataset with id "<datasetId>".

Request Body

Content Types: */*, application/json

update(actor_id, body, opts \\ [])

@spec update(
  actor_id :: String.t(),
  body :: map() | ApifyClient.Schemas.UpdateActorRequest.t(),
  opts :: keyword()
) ::
  {:ok, ApifyClient.Schemas.ActorResource.t()} | {:error, ApifyClient.Error.t()}

Update Actor

Updates an Actor's settings with the values specified in an Actor object passed as JSON in the POST payload. Only the fields specified in the request body are updated.

Returns the full Actor object, the same as the Get Actor endpoint.

In the HTTP request, set the Content-Type header to application/json.

Authentication

To provide the authentication token, we recommend using the request's Authorization header, rather than the URL. For details, see Authentication.

Make an Actor public

To make your Actor public:

Update build tags

To change tags assigned to Actor builds, use the taggedBuilds object. It's a dictionary that maps tag names to specific builds, where:

  • the key is the tag name, for example latest or beta
  • the value is either null or an object with a build ID

Changing tags is a patch operation. Only the tags that you provide in this object are updated.

Note that you can assign multiple tags to a single build, but you can't assign the same tag to multiple builds.

  • To create or reassign a tag, provide the tag name with a build ID. For example, to assign the latest tag to a build, use:
{
  "latest": { "buildId": "z2EryhbfhgSyqj6Hn" }
}
  • To remove a tag from a build, provide the tag name with a null value. For example, to remove the beta tag, use:
{
  "beta": null
}
  • You can perform multiple actions at once. The following example reassigns latest and removes beta, while preserving other existing tags:
{
  "latest": { "buildId": "z2EryhbfhgSyqj6Hn" },
  "beta": null
}

Request Body

Content Types: application/json

validate_input(actor_id, body, opts \\ [])

@spec validate_input(actor_id :: String.t(), body :: map(), opts :: keyword()) ::
  {:ok, validate_input_200_json_resp()} | {:error, ApifyClient.Error.t()}

Validate Actor input

Validates the JSON payload against the Actor's input schema defined in the specified build.

If the specified build has no input schema, any input is considered valid.

Options

  • build: Actor build whose input schema is used for validation. Can be a build tag or build number. Defaults to the latest build tag.

Request Body

Content Types: application/json

The Actor input as a JSON object.

You can omit fields that have a default in the input schema. They're filled in before validation.